Loki的TypeList技术解析(二)
ct TypeAt; template
struct TypeAt
, 0> { typedef Head Result; }; template
struct TypeAt
, i> { typedef typename TypeAt
::Result Result; }; //////////////////////////////////////////////////////////////////////////////// // class template TypeAtNonStrict // Finds the type at a given index in a typelist // Invocations (TList is a typelist and index is a compile-time integral // constant): // a) TypeAt
::Result // returns the type in position 'index' in TList, or NullType if index is // out-of-bounds // b) TypeAt
::Result // returns the type in position 'index' in TList, or D if index is out-of-bounds //////////////////////////////////////////////////////////////////////////////// template
struct TypeAtNonStrict { typedef DefaultType Result; }; template
struct TypeAtNonStrict
, 0, DefaultType> { typedef Head Result; }; template
struct TypeAtNonStrict
, i, DefaultType> { typedef typename TypeAtNonStrict
::Result Result; }; //////////////////////////////////////////////////////////////////////////////// // class template IndexOf // Finds the index of a type in a typelist // Invocation (TList is a typelist and T is a type): // IndexOf
::value // returns the position of T in TList, or NullType if T is not found in TList //////////////////////////////////////////////////////////////////////////////// template
struct IndexOf; template
struct IndexOf
{ enum { value = -1 }; }; template
struct IndexOf
, T> { enum { value = 0 }; }; template
struct IndexOf
, T> { private: enum { temp = IndexOf
::value }; public: enum { value = (temp == -1 -1 : 1 + temp) }; }; //////////////////////////////////////////////////////////////////////////////// // class template Append // Appends a type or a typelist to another // Invocation (TList is a typelist and T is either a type or a typelist): // Append
::Result // returns a typelist that is TList followed by T and NullType-terminated //////////////////////////////////////////////////////////////////////////////// template
struct Append; template <> struct Append
{ typedef NullType Result; }; template
struct Append
{ typedef Typelist
Result; }; template
struct Append
> { typedef Typelist
Result; }; template
struct Append
, T> { typedef Typelist
::Result> Result; }; //////////////////////////////////////////////////////////////////////////////// // class template Erase // Erases the first occurence, if any, of a type in a typelist // Invocation (TList is a typelist and T is a type): // Erase
::Result // returns a typelist that is TList without the first occurence of T //////////////////////////////////////////////////////////////////////////////// template
struct Erase; template
// Specialization 1 struct Erase
{ typedef NullType Result; }; template
// Specialization 2 struct Erase
, T> { typedef Tail Result; }; template
// Specialization 3 struct Erase
, T> { typedef Typelist
::Result> Result; }; //////////////////////////////////////////////////////////////////////////////// // class template EraseAll // Erases all first occurences, if any, of a type in a typelist // Invocation (TList is a typelist and T is a type): // EraseAll
::Result // returns a typelist that is TList without any occurence of T //////////////////////////////////////////////////////////////////////////////// template
struct EraseAll; template
struct EraseAll
{ typedef NullType Result; }; template
struct EraseAll