Boost logo

Boost Users :

Subject: Re: [Boost-users] boost::lambda: how to create indirect functor
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-02-05 12:06:31


AMDG

@ wrote:
> prerequisites:
>
> struct C {
> void func(int i) {}
> };
>
> void indirect(boost::function<void(C*)> f)
> {
> static C c;
> f(&c);
> }
>
> I need a functor that takes int and calls "indirect" passing there &C::func
> bound with that int.
>
> I imagine a solution like:
>
> boost::function<void(int)> result_functor = bind(indirect, bind(&C::func,
> protect(_1), _1));
>
> receiving compilation error: "could not deduce argument" deep inside lambda
> library
>

Lambda doesn't allow you to mix arguments from multiple nested binds.
In other words, you would need to use protect on the inner bind, to keep
it from being evaluated immediately, but that causes _1 to refer to the
inner _1,
not the outer _1.

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