Boost logo

Boost :

From: Giovanni Bajo (giovannibajo_at_[hidden])
Date: 2002-04-18 08:41:01

----- Original Message -----
From: "Douglas Gregor" <gregod_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Thursday, April 18, 2002 1:20 AM
Subject: Re: [boost] Loki Functor

> > Of course, the function objects returned by bind2() can't be called in
> > way, while bind2()() is "complete".
> I see. I'm still not sure that the name 'chain' is best for this task.
> something like 'join' or 'combine'?

I'm not a native speaker, and 'chain' sounded good enough to my ear :)
I don't like 'combine', because it sounds too much as 'compose' to me, which
is a compeltely different issue.

Anyway, I find the bind2 syntax good enough, even if it not scales up very
well to more than two functions.

bind2(foo, _1)(bind2(bar, _2)(foobar, _3)); // asymmetrical, unreadable
bind(foo, _1) + bind(bar, _2) + bind(foobar, _3); // uhuh, sorry, but I
had to try again ;)
bind3(foo, _1)(bar, _2)(foobar, _3); // too many classes to be defined
bind<3>(foo, _1)(bar, _2)(foobar, _3); // might work, depends on the
implementation of bind
bind(foo, _1).bind(bar, _2).bind(foobar, _3); // member function bind() to
add an element to the chain

I like the last two. Even if we do it within bind, a global chain() function
could be implemented to increase the readability:

template <typename F1, typename F2>
VeryComplexTrait<F1,F2>::type chain(F1 f, F2, g)
{ return bind(f).bind(g); }

Note that you can still bind the result of this operation, like:

bind(chain(foo, bar, foobar), _3, _2, _1); // reverse parameters

> No, you understood the problem correctly. And while arity traits are fine,
> they aren't there for already-existing function objects (and there are a
> of function objects out there). Note that a Lambda-only or Bind-only
> (the Lambda solution is much cleaner) doesn't require these types of

That's right. The same problem exists for the return function, since bind()
requires "value_type". Anyway, I now like the solution above, with bind only

Giovanni Bajo

Boost list run by bdawes at, gregod at, cpdaniel at, john at