
15 Feb
2006
15 Feb
'06
9:25 p.m.
Me here wrote:
Hello,
I want to make a binder to do an assignment like:
------ example ------ #include "boost/bind.hpp"
int main() { int X = 0;
boost::bind<int&>(X, _1)( 1 );
return 0; } --- end ---
But is does not compile. I know that I can write small function, but I already wrote too much such small functions.
You need a small function, sorry. :-) struct assign { template<class T> T& operator()( T& t, T v ) const { t = v; } }; int main() { int X = 0; boost::bind<int&>( assign(), boost::ref(X), _1 )( 1 ); } Or you can use Lambda, of course.