$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
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
something like:
unspecified compose(Tuple t, F f)
{
return compose(tail(t), bind(head(t), f)),
}
F compose(EmptyTuple, F f)
{
return 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
sure.
Also, if you can't use typeof, you would have to get into bind's
implementation details to calculate the return type.
FWIW.
Regards,
Arkadiy