3.15 Typelist Quick Facts
Header file:
Typelist.h.
All typelist utilities reside in namespace Loki::TL.
Class template Typelist<Head, Tail> is defined.
Typelist creation: Macros TYPELIST_1 to TYPELIST_50 are defined. They accept the number of parameters stated in their name.
The upper limit of macros (50) can be extended by the user. For instance:
#define TYPELIST_51(T1, repeat here up to T51) \
Typelist<T1, TYPELIST_50(T2, repeat here up to T51) >
By convention, typelists are proper—they always have a simple type (nontypelist) as the first element (the head). The tail can only be a typelist or NullType.
The header defines a collection of primitives that operate on typelists. By convention, all the primitives return the result in a nested (inner) public type definition called Result. If the result of the primitive is a value, then its name is value.
The primitives are described in Table 3.1.
Synopsis of class template GenScatterHierarchy:
template <class TList, template <class> class Unit>
class GenScatterHierarchy;
GenScatterHierarchy generates a hierarchy that instantiates Unit with each type in the typelist TList. An instantiation of GenScatterHierarchy directly or indirectly inherits Unit<T> for each T in TList.
The structure of a hierarchy generated by GenScatterHierarchy is depicted in Figure 3.2.
Synopsis of class template GenLinearHierarchy:
template <class TList, template <class, class> class Unit>
class GenLinearHierarchy;
GenLinearHierarchy generates a linear hierarchy, depicted in Figure 3.6.
GenLinearHierarchy instantiates Unit by passing each type in the typelist TList as Unit's first template argument. Important: Unit must derive publicly from its second template parameter.
The overloaded Field functions provide by-type and by-index access to the nodes of the hierarchies.
Field<Type>(obj) returns a reference to the Unit instantiation that corresponds to the specified type Type.
Field<index>(obj) returns a reference to the Unit instantiation that corresponds to the type found in the typelist at the position specified by the integral constant index.
Table 3.1. Compile-Time Algorithms Operating on Typelists
Length<TList> |
Computes the length of TList. |
TypeAt<TList, idx> |
Returns the type at a given position (zero-based) in TList. If the index is greater than or equal to the length of TList, a compile-time error occurs. |
TypeAtNonStrict<TList, idx> |
Returns the type at a given position (zero-based) in a typelist. If the index is greater than or equal to the length of TList, Null Type is returned. |
IndexOf<TList, T> |
Returns the index of the first occurrence of type T in typelist TList. If the type is not found, the result is -1. |
Append<TList, T> |
Appends a type or a typelist to TList. |
Erase<TList, T> |
Erases the first occurrence, if any, of T in TList. |
EraseAll<TList, T> |
Erases all occurrences, if any, of T in TList. |
NoDuplicates<TList> |
Eliminates all the duplicates from TList. |
Replace<TList, T, U> |
Replaces the first occurrence, if any, of T in TList with U. |
ReplaceAll<TList, T, U> |
Replaces all occurrences, if any, of T in TList with U. |
MostDerived<TList, T> |
Returns the most derived type from T in TList. If no such type is found, T is returned. |
DerivedToFront<TList> |
Brings the most derived types to the front of TList. |
|