
boost-users-bounces@lists.boost.org, le :
Thanks Peter, this makes sense. But just image I cannot change the print function's interface. For example I have to interface with MFC's CComboBox::AddString( LPCTSTR lpszString ) . Do you think there is still a way to have just one for_each() loop? My guts tell me no.
A while ago, I posted a very similar question, which was not answered: http://groups.google.ca/group/boost-list/browse_thread/thread/c24afb8e21 26fc88/b372145c0385d381?lnk=st&q=emalenfant+boost&rnum=1&hl=fr#b372145c0 385d381. In there, I was asking for comments about 2 workarounds which, adapted to your case would be: 1) var_typestd::string::type temp(var(std::string())); std::for_each( begin, end, ( temp = bind(&A::name, _1), bind(Print, bind(&std::string::c_str, temp)) ) ); 2) var_typestd::string::type temp(var(std::string())); std::for_each( begin, end, bind(Print, bind(&std::string::c_str, (temp = bind(&A::name, _1)) ) ) ); Note that this is more "for fun" than, anything. None of these is very elegant, or efficient...