Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-04-18 08:37:44


From: "Giovanni Bajo" <giovannibajo_at_[hidden]>
> >
> > I would expect a bind-only solution to be
> >
> > bind(foo, _1, _2), bind(bar, _3, _4).
> >
> > It happens to be implemented already in Lambda.
>
> Several issues:
>
> - Might be my personal opinion, but the comma operator is _awful_. It's
> unclear, error-prone, and it's always been suggested against its use, in
any
> single book I can think of. Among other things, you have to always cover
it
> around parenthesis otherwise it gets evaluated as a list of parameters.
And
>
> func = bind(foo,_1,_2), bind(bar, _3, _4); // not even sure if it works
or
> requires parenthesis.
>
> is less clear than:
>
> func = bind(foo, _1,_2) + bind(bar, _3, _4);
> func = bind2(foo,_1,_2)(bar, _3,_4);

Awful or not, the comma operator is the C++ chaining operator.

bind(foo, _1, _2) + bind(bar, _3, _4)

means

foo(_1, _2) + bar(_3, _4).

In general,

bind(foo, _1, _2) @ bind(bar, _3, _4)

means

foo(_1, _2) @ bar(_3, _4).

> - boost::bind and lambda::bind cannot coexist so easily in the same code
> right now for a very simple reason: they both use "_N" as placeholders. If
> you include "boost/bind.hpp", you have to do:
>
> func = lambda::bind(lambda::_1, lambda::_2);

Do they need to? Why would you use boost::bind if you can use Lambda?


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