Binding function call to an assignment

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. I want to use this functor with smart_ptr, which allows to call a function, but I need an assignment. Your advice, please. Alexander __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com

-----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Me here Sent: Wednesday, February 15, 2006 10:24 AM To: boost@lists.boost.org Subject: [boost] Binding function call to an assignment
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 ---
You could use lambda: #include <boost/lambda/lambda.hpp> int main() { int X = 0; const int y = 1; namespace ll = boost::lambda; (ll::var(X) = ll::_1)(y) return 0; } Brock

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.
participants (3)
-
Brock Peabody
-
Me here
-
Peter Dimov