Boost logo

Boost :

From: Giovanni Piero Deretta (gpderetta_at_[hidden])
Date: 2008-06-18 04:36:18


On Tue, Jun 17, 2008 at 9:31 PM, albert meyburgh <ameyburgh_at_[hidden]> wrote:
> I believe this is a bug in the boost lambda constructor
>
> I have worked around the problem with this wrapper:
>
> template< typename T >
> struct LambdaConstructorWrapper : public boost::lambda::constructor< T >
> {
> typedef T result_type;
> };
>
> and using it as such:
>
> LambdaConstructorWrapper<MyType> myTypeConstructionWrapper;
>
> std::transform(
> mycontainer.begin(),
> mycontainer.end(),
> std::back_inserter( redcontainer ),
> boost::bind(myTypeConstructionWrapper, _1,
> WHATEVER_PARM));
>
> It seems to behave as expected by adding this one typedef so it's probably a
> bug? unless by design it's not supposed to be used this way for some reason
> that I don't see?
>

This is not a bug.

As other have said, use boost::*lambda*::bind, not plain bind. Bind
expect its first parameter to be a function pointer or a function
object which exposes a result_type typedef for result type deduction.

Boost.Lambda cannot have a result_type typedef because (in general)
the result type depends on the argument type. Boost.Lambda uses the
'sig' protocol for that, which boost.bind doesn't support.
boost::lambda::bind does.

Of course in a perfect world both boost.bind and boost.lambda would be
result_of compatible and these problems won't exist :)

HTH,

-- 
gpd

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk