Robert Jones:
On Thu, Oct 16, 2008 at 11:12 PM, Peter Dimov
wrote: With boost::bind, which doesn't evaluate its first argument, you'll need to use apply<>, as explained in
http://www.boost.org/doc/libs/1_36_0/libs/bind/bind.html#nested_binds
I understand the "how" of that, but not the "why". Why does bind not evaluate if first argument?
With apologies for the late response: The first argument is not evaluated because this is what's needed most often. It's common to use bind as an implementation detail as in template<class F> void g1( F f ) { g2( boost::bind( f, _2, _1 ) ); } and, since the caller of g1 may well pass boost::bind(...) to it, evaluating f would mean more boost::protect's. The evaluation of the first argument is practically only needed for cases of the form bind( _1, _2 ). We could have made it so that placeholders are evaluated, but nested binds are not; this would cover nearly all use cases. The reason for not doing that in boost::bind is technical (and somewhat historical): the object returned by boost::bind always has a fixed result_type, and bind( _1, _2 ) cannot have one. There is no technical reason that prevents bind<R>( _1, _2 ) from being handled, though. I just missed this possibility, and nobody has suggested it (to the best of my knowledge). -- Peter Dimov http://www.pdplayer.com