boost::function & boost::lambda - call site invocation & accessing _1 and _2 as the type

Posted by John Dibling on Stack Overflow See other posts from Stack Overflow or by John Dibling
Published on 2010-06-05T18:38:41Z Indexed on 2010/06/05 18:42 UTC
Read the original article Hit count: 150

Filed under:
|

Sorry for the confusing title. Let me explain via code:

#include <string>
#include <boost\function.hpp>
#include <boost\lambda\lambda.hpp>
#include <iostream>

int main()
{
    using namespace boost::lambda;

    boost::function<std::string(std::string, std::string)> f =
        _1.append(_2);

    std::string s = f("Hello", "There");
    std::cout << s;

    return 0;
}

I'm trying to use function to create a function that uses the labda expressions to create a new return value, and invoke that function at the call site, s = f("Hello", "There");

When I compile this, I get:

1>------ Build started: Project: hacks, Configuration: Debug x64 ------
1>Compiling...
1>main.cpp
1>.\main.cpp(11) : error C2039: 'append' : is not a member of 'boost::lambda::lambda_functor<T>'
1>        with
1>        [
1>            T=boost::lambda::placeholder<1>
1>        ]

Using MSVC 9.

My fundamental understanding of function and lambdas may be lacking. The tutorials and docs did not help so far this morning.

How do I do what I'm trying to do?

© Stack Overflow or respective owner

Related posts about c++

Related posts about boost