nested bind() does not compile

Hello
I'm wondering why the attached code which is using nested boost::bind()
does not compile on GCC ( I have tried 4.1 and 4.3). According to the
"bind" package documentation nested bind() calls are allowed.
To make it compile (and work!) it's necessary to add explicit cast to the
result of the nested bind() call, like:
boost::function

AMDG Serguei Kolos wrote:
I'm wondering why the attached code which is using nested boost::bind() does not compile on GCC ( I have tried 4.1 and 4.3). According to the "bind" package documentation nested bind() calls are allowed. To make it compile (and work!) it's necessary to add explicit cast to the result of the nested bind() call, like:
boost::function
f = boost::bind( wrapper, a, (boost::function )boost::bind( cb, p ), b ); But that is something which I don't like. Any ideas?
Use boost::protect. The problem is that nested binds are handled specially: boost::bind( wrapper, a, boost::bind( c, p ), b ); creates a function object that executes wrapper(a, c(p), b). what you want is wrapper(a, boost::bind( c, p ), b), so you have to write boost::bind( wrapper, a, boost::protect(boost::bind( c, p )), b ); In Christ, Steven Watanabe

Hi Thanks, that works perfectly. In fact the bind documentation does mention that function but I somehow overlooked it. Cheers, Sergei Steven Watanabe wrote:
AMDG
Serguei Kolos wrote:
I'm wondering why the attached code which is using nested boost::bind() does not compile on GCC ( I have tried 4.1 and 4.3). According to the "bind" package documentation nested bind() calls are allowed. To make it compile (and work!) it's necessary to add explicit cast to the result of the nested bind() call, like:
boost::function
f = boost::bind( wrapper, a, (boost::function )boost::bind( cb, p ), b ); But that is something which I don't like. Any ideas?
Use boost::protect.
The problem is that nested binds are handled specially:
boost::bind( wrapper, a, boost::bind( c, p ), b ); creates a function object that executes wrapper(a, c(p), b). what you want is wrapper(a, boost::bind( c, p ), b), so you have to write boost::bind( wrapper, a, boost::protect(boost::bind( c, p )), b );
In Christ, Steven Watanabe
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

On Wed, Jul 14, 2010 at 7:30 PM, Steven Watanabe
AMDG
boost::bind( wrapper, a, boost::bind( c, p ), b ); creates a function object that executes wrapper(a, c(p), b). what you want is wrapper(a, boost::bind( c, p ), b), so you have to write boost::bind( wrapper, a, boost::protect(boost::bind( c, p )), b );
In Christ,
I know I'm being really dim here, but I have a strange mental block about protect, so for the hard-of-thinking can you explain the difference between boost::bind( wrapper, a, boost::bind( c, p ), b ); and boost::bind( wrapper, a, boost::protect(boost::bind( c, p )), b ); Thanks, - Rob.

AMDG Robert Jones wrote:
On Wed, Jul 14, 2010 at 7:30 PM, Steven Watanabe
wrote: boost::bind( wrapper, a, boost::bind( c, p ), b ); creates a function object that executes wrapper(a, c(p), b). what you want is wrapper(a, boost::bind( c, p ), b), so you have to write boost::bind( wrapper, a, boost::protect(boost::bind( c, p )), b );
I know I'm being really dim here, but I have a strange mental block about protect, so for the hard-of-thinking can you explain the difference between
boost::bind( wrapper, a, boost::bind( c, p ), b );
and
boost::bind( wrapper, a, boost::protect(boost::bind( c, p )), b );
The usual behavior of nested binds is to evaluate them all at once like: wrapper(a, c(p), b). Note that this means that when evaluating a bind, we first recurse into all nested binds. protect prevents this. A bind object that has been protected is treated like any other argument giving: wrapper(a, boost::protect(boost::bind( c, p )), b) In Christ, Steven Watanabe
participants (3)
-
Robert Jones
-
Serguei Kolos
-
Steven Watanabe