Boost logo

Boost :

From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2002-12-17 06:21:19


David A. Greene wrote:
> Well, that's not creating a boost::tuple. :) I could certainly use
> mpl::fold or some similar algorithm to create boost::tuple<int,
> boost::tuple<...> > > > but I'm not sure that "really" a boost::tuple
> either. cons<int, cons<...> > > > might be closer.

Yep, the later will give you all the functionality of
'boost::tuple<int,...>' except the constructors and assignment from
'std::pair'. A generator for it is as simple as this:

    template< typename Types > struct tuple_gen
        : fold_backward<
              Types
            , boost::tuples::null_type
            , boost::tuples::cons<_2,_1>
>
    {
    };

    tuple_gen< list<int,char const*,bool> >::type t;

See
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/boost/boost/libs/m
pl/example/tuple_from_list.cpp for the complete example.

> And I still don't completely "get" inherit_linearly.

It's a synonym for 'fold< Types,Root,NodeFunc >'.

> I assume it is supposed to be something like Loki's GenLinearHierarchy.

It is capable of producing both single-base (the example you've seen) and
mutliple-base class hierarchies
(http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/boost/boost/libs/
mpl/example/inherit_multiply.cpp), the later with a help of 'inherit'
metafunction.

Aleksey


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk