|
Boost : |
From: Giovanni Bajo (giovannibajo_at_[hidden])
Date: 2002-04-17 16:48:52
----- Original Message -----
From: "Douglas Gregor" <gregod_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Wednesday, April 17, 2002 10:32 PM
Subject: Re: [boost] Loki Functor
> Of course, the + operator becomes ambiguous once we starting talking about
> Lambda. I don't like the use of + for chaining anymore :)
too bad :)
> 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.
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.
Of course, the function objects returned by bind2() can't be called in any
way, while bind2()() is "complete".
> 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?
template <typename F>
struct ArityTrait;
template <typename R, typename A>
struct ArityTrait<R (*)(A)>
{ enum { value = 1 }; };
template <typename R, typename A, typename B>
struct ArityTrait<R (*)(A, B)>
{ enum { value = 2 }; };
template <typename F>
int CalcArity(F f)
{
return ArityTrait<F>::value;
}
void Foo(int a, float b) {}
void Bar(int c) {}
int main()
{
printf("Foo's arity: %d\n", CalcArity(Foo));
printf("Bar's arity: %d\n", CalcArity(Bar));
}
Or did I misunderstand the problem?
Giovanni Bajo
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk