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
(set<string>::*INSERT)(const string&);
set<string> str_con;
INSERT insert_func = &set<string>::insert;
vector v2;
v2.push_back( test_str("one") );
v2.push_back( test_str("two") );
boost::function f =
bind(&test_str::str, Arg);
//for_each( v2.begin(), v2.end(), bind(
insert_func, var(str_con), var(f)));
for_each( v2.begin(), v2.end(), bind( insert_func,
var(str_con), bind(&test_str::str, Arg)));
return 0;
}
This is part of the error message i get from a
vs2003.net compiler.
Any help would be appreciated.
c:\santosh\tools\boost_1_33_1\boost\lambda\detail\function_adaptors.hpp(250):
error C2664: 'std::pair<_Ty1,_Ty2> (Arg1)' : cannot
convert parameter 1 from 'boost::function<Signature>'
to 'const std::basic_string<_Elem,_Traits,_Ax> '
with
[
_Ty1=std::_Treestd::string,std::allocatorstd::string,false>>::iterator,
_Ty2=bool,
Arg1=const std::string &
]
and
[
Signature=std::string &(test_str &)
]
and
[
_Elem=char,
_Traits=std::char_traits<char>,
_Ax=std::allocator<char>
]
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com