From: Joel de Guzman (joel_at_[hidden])
Date: 2003-11-13 18:05:45
Bernard <yahoo_at_[hidden]> wrote:
> I've been discovering boost::MPL and I think it's very powerful ( even
> if I could not find documentations on mpl::apply and mpl::bind :-(,
> is there any ?)
> When I've been using tuples, I noticed that boost::tuples::elements<>
> takes an int, and I think it prevents me from mpl::binding this
> Is there any reason not to overload it with and mpl::int_<> argument ?
> Also, I've been writing my own code similar to tuples::for_each from
> tuple_ext (from boost files section) seems and it seems to fill an
> obvious need, will is be released ?
> Now, to my main question ! ( last three do not count :-) )
> I would like to compute a tuple from a tuple of tuples.
> I can do the static part of computing my resulting tuple type with
> mpl. How could I fill my resulting tuple with the coresponding values
> from the processed tuple ?
Ok, so you have an mpl sequence that you want to build a tuple
from? Is that it?
> It seems I should be able to conditionally instanciate fetching
> functions, but I do not really see how to do it and I'd hate to
> discover that some booster already did it much better.
> (I would like to collect the N'th element (if it exists) of each tuple
> from a tuple of tuples, and have them in a resulting tuple).
Aha!.... what you need is "transform" passing in your tuple of tuples
and a polymorphic functor that returns the N'th element (if it exists
--what if it doesn't?). It would be something like:
template <typename Tuple>
typedef typename get_nth_element_if_it_exists<Tuple>::type type;
template <typename Tuple>
operator()(Tuple const& t)
There's a library (currently in the boost-sandbox under the spirit directory)
code-named fusion. It is a work in progress based on the TR1 tuple
implementation that Jaakko and I wrote a few months ago (also in the
boost-sandbox). This is a re-implementation of the TR1 tuples with iterators,
views and algorithms. The structure is somewhat modeled after MPL. I
code-named it "Fusion" because the library reminds me of the "Fusion" of
compile time metaprogramming with runtime programming.
Right now, I'm working on making it feature complete plus documentation,
and the tough part--porting to vintage compilers (VC6 and borland).
Check it out. See the readme file for a brief synopsis on what's available.
-- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk