Representing of empty sequence

Hi All, 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; }; template <class T0, class T1> struct vector2 { typedef vector2 type; }; template <class T0, class T1, class T2> struct vector3 { typedef vector3 type; }; struct dummy; template <class T0 = dummy, class T1 = dummy, class T2 = dummy> struct vector; template<T0> struct vector : vector1<T0> {}; template <T0, T1> struct vector : vector2 <T0, T1> {}; template <T0, T1, T2> struct vector : vector3 <T0, T1, T2> {}; Examples: vector1<char>::type vector2<int, long>::type vector3<short, int, long>::type vector<char>::type vector<int, long>::type vector<bool, float, double>::type How to declare and make use of an empty sequence? Rgds, anna -- Flow: For Love of Water http://missingrainbow.blogspot.com/2008/09/flow-for-love-of-water.html

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
participants (2)
-
Missing Rainbow
-
Steven Watanabe