|
Boost : |
From: Giovanni Bajo (giovannibajo_at_[hidden])
Date: 2002-04-18 08:26:05
> > And if you take me example, you see that bind() is used to redistribute
> the
> > arguments. chain() just makes sure that all the arguments are correctly
> > exposed. A bind-only solution would be something weird like:
> >
> > bind2(foo, _1, _2)(bar, _3, _4);
> > bind2(foo, _1, _2)(bar, _1, _2); // call both with the same parameters.
>
> 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);
Ok my opinion here, your mileage may vary etc.
- 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);
So, you either use one or the other, or specify namespace for placeholders
(bleah). I understand the long-time plan would be to unify the two
libraries, but it'd probably take a while. Moreover, I read that
boost::bind() is likely to become std, while lambda library is not yet an
official boost library.
- Users may require function chaining, but their compiler does not support
lambda. And they might not want to convert all the existing code base to
lambda::bind just because of this feature. I mean, I think that
boost::bind() is very powerful and fits the needs of many users under many
situations.
- I can't find in the documentation if lambda::bind() must be unlambda'd
before being able to be stored in a function<>. Either way, my code does not
compile. Actually, even function<int,int,int> f = unlambda(_1 + _2) doesn't
compile. It might be the compiler I've tested it with (GCC 2.95.3, which is
reasonably enough compliant), but would you please provide the full code to
chain two functions/functors, exposing both set of parameters, and store the
result into a function<>?
Giovanni Bajo
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk