boost function with lambda bind
I'm trying to use a boost function object within a
lambda bind. This is my test program and the commented
line does not compile. What i'm trying to do is
iterate over a container of test_str structs which has
one data member (a string) and get that string and
insert that string into another string.
#include <string>
#include <set>
#include <vector>
#include <iostream>
#include "boost/lambda/lambda.hpp"
#include "boost/lambda/bind.hpp"
#include <algorithm>
#include "boost/function.hpp"
using namespace std;
struct test_str
{
test_str(string s): str(s){}
string str;
};
int main(int argc, char* argv[])
{
using namespace boost::lambda;
boost::lambda::placeholder1_type Arg;
typedef pair
On 12/10/06, Santosh Joseph
boost::function
f = bind(&test_str::str, Arg); //for_each( v2.begin(), v2.end(), bind( insert_func, var(str_con), var(f)));
I think this is because f is a is a boost::function object. You'e trying to pass a functor object to a function that takes a std::string& argument, and that's what the error is saying that it can't coerce f to a std::string type. Instead of using a boost::function<...> object try passing it directly to the expression, like as follows. for_each( v2.begin(), v2.end(), bind( insert_func, var(str_con), bind(&test_str::str, Arg))); the boost::lambda::bind function returns a lambda functor. HTH
participants (2)
-
Haroon Khan
-
Santosh Joseph