|
Boost : |
From: Douglas Gregor (gregod_at_[hidden])
Date: 2002-04-17 15:32:30
On Wednesday 17 April 2002 03:54 pm, you wrote:
> > And because we can't overload '+' for the general case, I think we
>
> shouldn't
>
> > overload '+' for just boost::function.
>
> Ok, got it. I'm not sure I agree completely, after all we could just
> overload operator+() as possible, where at least one parameter is the
> result of bind() or a function<>, and just as an alternative syntax to a
> more generic chain(). After all, lambda functions work only when you have a
> lamba placeholder near-ish the begin of the function itself (see the famous
> "cout << "\n" << _1" example), so users are (or will be) already smart
> enough to understand that overloaded operators work only if you have the
> right classes around them.
Of course, the + operator becomes ambiguous once we starting talking about
Lambda. I don't like the use of + for chaining anymore :)
> Your example brings up also the issue with parameter chaining. From the
> code you wrote, you expect that the results of chain(foo, bar) is a
> function object that accepts a single parameter, which must be convertible
> to both foo's and bar's parameter. I don't think this is a general enough
> solution, since it couldn't handle cases where foo and bar have completely
> different signatures. My proposal was to have chain(foo,bar) return a
> function objects that must be called with all parameters of foo, followed
> by all parameters of bar. The example above would have to be changed as:
>
> for_each(people.begin(), people.end(), bind(chain(foo, bar), _1, _1));
>
> Even if it makes your example more complex, it gives a total flexibility to
> chain(), that's now able to chain any couple of function objects, just like
> bind() is able to bind any parameter in any order.
>
> Giovanni Bajo
This goes way beyond what I would consider chaining; for anything where I
want to take several arguments and redistribute them to one or more
operations (including changes in ordering, duplication, etc.) I expect to use
a binding library. Chaining, to me, is just the simple operation that says
"let one event trigger a chain of similar events".
There is one technical issue with implementing your suggestion: we don't know
the relative arities of 'foo' and 'bar'. For instance:
do_something(bind(chain(foo, bar), _1, _2, _1, _3, _2));
How many arguments does 'foo' get?
Doug
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk