Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6646515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:25:31+00:00 2026-05-26T00:25:31+00:00

I am currently doing some exercises with templated functions. I had the task to

  • 0

I am currently doing some exercises with templated functions.
I had the task to write a implementation of the transform algorithm.
I did it like the following and it works:

template <class in, class out, class T>
out stransform(in b, in e, out d, T p(const T&)) {
    while (b != e) 
        *d++ = p(*b++);
    return d;
}

As with the normal transform I have to call the predicate with an explicit type like

stransform(begin(vec1), end(vec1), back_inserter(vec2), predi<double>);

Now, I stumbled upon the C++11 Lambdas and wanted to call my function like this:

stransform(begin(vec1), end(vec1), back_inserter(vec2), [] (double x) ->double {return x * 10;} );

With that I do get a compiler error that the type cant be deduced.
This is the thing I dont understand as I am defining the T type in my lambda actually twice.

I did also check back the original transform function, with which it is working. I then checked the implementation of that one and it is obviously implemented with a template class for the whole function.
Is that the correct way for implementing predicates with templates?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:25:31+00:00Added an answer on May 26, 2026 at 12:25 am

    The predicate is normally a simple template argument:

    template <class in, class out, class UnaryPredicate>
    out stransform(in b, in e, out d, UnaryPredicate p); 
    

    This will accept pointers to function, lambdas and function objects.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently doing something like this in some code I'm working on right now:
I'm currently doing some GUI testing on a ASP.net 2.0 application. The RDBMS is
i'm currently doing some reports for SSRS, and i just confirm what i already
I am currently doing some socket programming using C/C++. To be able to use
We're currently doing some Word automation, and want to be able to insert a
Currently I'm doing some unit tests which are executed from bash. Unit tests are
I'm currently doing the following to use typed datasets in vs2008: Right click on
I am currently doing a code review and the following code made me jump.
I'm currently doing some tests using Cairo to replace some existing GDI/GDI+ code in
I am currently doing some upgrades to our very simple logging library, and I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.