From: Arkadiy Vertleyb (vertleyb_at_[hidden])
Date: 2006-11-03 11:41:29
"Fernando Cacciola" <fernando_cacciola_at_[hidden]> wrote
> Say I have a few arbitraty function objects:
> A a ; B b ; C c ;
> I can easily pipe them toghether using Boost.Bind:
> bind(a, bind(b, bind(c,_1) ) )(some_starting_value);
> But how do I create such a composed functor programatically from an
> aribtrary tuple of function objects, as in tuple<A,B,C>?
> The idea is to present to the user a simple interface were he pass just a
> tuple of functors and I do the magic of turning them into a pipe.
I think you may need Fusion to do this... The pseudocode would be roughly
unspecified compose(Tuple t, F f)
return compose(tail(t), bind(head(t), f)),
F compose(EmptyTuple, F f)
compose(tuple(a, b, c), _1)
(except I think the order may be inverted)
But I don't think current boost::tuple allows for extracting head and tail.
Fusion may also have some kind of "fold" algorithm to do this, but I am not
Also, if you can't use typeof, you would have to get into bind's
implementation details to calculate the return type.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk