Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2006-02-15 16:25:27


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.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk