Boost logo

Boost Users :

Subject: Re: [Boost-users] nested bind() does not compile
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2010-07-14 14:30:51


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<void ( void )> f =
> boost::bind( wrapper, a, (boost::function<bool
> (void)>)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 list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net