Boost logo

Boost Users :

Subject: Re: [Boost-users] compile errors with boost::bind
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2010-06-16 21:12:18


AMDG

Nathan Ridge wrote:
> I'm getting some compiler errors with boost::bind that I'm not able to figure out.
>
> I was able to reduce it to the following minimal example:
>
>
> #include <boost/bind.hpp>
>
> using boost::bind;
>
> template <typename RawProc>
> void AdapterProc(RawProc proc)
> {
> // do other stuff, then call proc()
> }
>
> template <typename RawProc>
> void f(RawProc proc)
> {
> bind(&AdapterProc<RawProc>, proc)();
> }
>
> void RawProc(int x);
>
> int main()
> {
> f(bind(&RawProc, 0));
> }
>

This resolves to bind(&AdapterProc<RawProc>, bind(&RawProc, 0))().
Nested binds are handled specially, so this is evaluated as
AdapterProc(RawProc(0))

you need to wrap proc with boost::protect (from boost/bind/protect.hpp)
in f.

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