Boost logo

Boost Users :

Subject: Re: [Boost-users] Representing of empty sequence
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2008-10-13 19:42:17


AMDG

Missing Rainbow wrote:
> I am trying to understand the implementation of mpl::vector. I have
> simplified greatly to help understand it. I am now trying to figure
> out how to represent an empty sequence. Here is what I have got:
>
> template <class T0>
> struct vector1
> {
> typedef vector1 type;
> };
>
> <snip>
>
> template<T0>
> struct vector : vector1<T0> {};
>
> <snip>
>
> How to declare and make use of an empty sequence?
>

The easiest way is to use a simple struct

struct vector0 {
    typedef vector0 type;
};

template<>
struct vector<> : vector0 {};

MPL uses a little trick to make vector0 consistent with vector1, etc.

template<class Dummy = na>
struct vector0 {
    typedef vector0 type;
};

template<>
struct vector<> : vector0<> {};

Note the the Dummy parameter is never expected to be
used. It just allows the use of <>.

In Christ,
Steven Watanabe


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net