
This works exactly as expected... void f( unsigned & val ) { val *= 2; } unsigned i = 3; boost::bind( f, _1)( i ); with i being doubled. What I don't get is why I don't need to say boost::bind( f, boost::ref( _1 ) )( i ); and conversely how I specify that I want bind to pass by value rather than by reference for the placeholder. Thanks - Rob.

AMDG Robert Jones wrote:
This works exactly as expected...
void f( unsigned & val ) { val *= 2; }
unsigned i = 3; boost::bind( f, _1)( i );
with i being doubled. What I don't get is why I don't need to say
boost::bind( f, boost::ref( _1 ) )( i );
and conversely how I specify that I want bind to pass by value rather than by reference for the placeholder.
boost::ref is only needed for objects that are stored in the function object. The arguments are always passed by reference. If you want pass by value, either make f pass by value, or explicitly copy the argument: template<class R> struct copy { typedef R result_type; R operator()(R r) const { return r; } }; bind(f, bind(copy<int>(), _1))(i) In Christ, Steven Watanabe
participants (2)
-
Robert Jones
-
Steven Watanabe