Hi All
I am trying to use boost lambda for looping over a std::map to get each
element and
pass those to a class function using lambda functions.
I don't know why but the binding inside my std::for_each is not compiling
and I have 2 errors
pointing to the line where boost::assign is used.
'invalid initialization of reference of type int&'
'invalid initialization of reference of type std::basic_string<>&'
Do you know how to fix this and why it is happening
Thank you very much
Regards
CS
//Boost
//#include
#include
#include
#include
#include
#include
class CInnerClassHandler{
public:
void DoSomething( int aIntValue, const std::string& aStringValue ){
std::cout << "INT:" << aIntValue
<< "STRING:" << aStringValue
<< std::endl; // here we just trace
}
};
void map_lambda_test(){
typedef std::pair< int, std::string > this_pair;
std::map< int, std::string > dictionary =
boost::assign::map_list_of(3,"A")(4,"B")(5,"C"); // Errors
points to
// this line of code
CInnerClassHandler obj;
std::for_each(
dictionary.begin(),
dictionary.end(),
boost::lambda::bind(
&CInnerClassHandler::DoSomething, &obj,
boost::lambda::bind(&this_pair::first,
boost::lambda::_1),
boost::lambda::bind(&this_pair::second,boost::lambda::_1))
);
}