Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2003-04-29 07:05:11


Joaquín Mª López Muñoz <joaquin_at_[hidden]> writes:

> Alexander Nasonov ha escrito:
>
>>
>
> [stuff deleted]
>
>>
>> Alternatively, you can implement MPL conformant sequence
>> tuple_sequence<Tuple>. It's not so hard as you can imagine.
>> (Question to MPL's authors: when it will be documented?).

Sequence requirements are already documented:
http://www.boost.org/libs/mpl/doc/ref/Sequence.html

You only need to make the apporpriate specializations of
mpl::begin/mpl::end. What _ought_ to be documented at
http://www.boost.org/libs/mpl/doc/ref/Reference/begin.html (but isn't)
is the default implementation of begin/end: you need that if you want
to a sequence for a compiler without partial specialization.

> I know it is not hard (candidate implementation follows): it is only that I
> do not want to rewrite the snippet if it happens to exist already somewhere
> into the Boost jungle.
>
> template <class Tuple,int N=0>
> struct tuple_to_sequence
> {
> BOOST_STATIC_CONSTANT(int,end=(N==tuples::length<Tuple>::value));
>
> typedef typename mpl::apply_if_c<
> end,
> mpl::identity<mpl::vector<> >,
> tuple_to_sequence<Tuple,N+1>
> >::type base;
>
> typedef typename mpl::apply_if_c<
> end,
> mpl::identity<tuples::null_type>,
> tuples::element<N,Tuple>
> >::type extra;
>
> typedef typename mpl::apply_if_c<
> end,
> mpl::identity<base>,
> mpl::push_front<base,extra>
> >::type type;
> };
>
> Regards,
>
> Joaquín M López Muñoz
> Telefónica, Investigación y Desarrollo

That's not (I think) what Alexander had in mind: IIUC he was talking
about a wrapper over tuples such that:

      tuple_sequence<some_tuple>

is an MPL sequence. Of course, a better solution would be to
specialize begin/end so that any Boost tuple is *itself* an MPL
sequence.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

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