Boost logo

Boost :

From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2008-06-10 09:35:39


AMDG

Robert Jones wrote:
> First - is "boost/lambda/bind.hpp" equivalent to "boost/bind.hpp"? Should it
> ever be necessary to include both?
>

Bind and Lambda are separate. If you are using Lambda you need to use
boost/lambda/bind.hpp which contains boost::lambda::bind.

> Second - Is it true that a lambda function is syntactically and semantically the
> same as a bind finction, eg
>
> Given:- int foo( int i ) { return i + 3; }
>
> Are these two expressions the same?
> bind( &foo, _1 );
> _1 + 3;
>

They should behave the same, unless this is
a boost::bind and you want to do further composition.

> Finally (for now!) - why is this wrong?
>
> struct A { string identity( string ) const; } a;
>
> vector<string> v;
> for_each( v.begin(), v.end(), cout << bind( &A::identity, a, _1 ) << '\n' );
>
> which is intended to output the return value of A::identity() for each
> element of v,
> separated by newlines.
>

It will only work if you using boost::lambda::bind, not boost::bind.

In Christ,
Steven Watanabe


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