|struct||KMakeTypeList< T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18 >|
|struct||KTypeList< T, U >|
|class||KTypeListIndexOf< TList, T >|
|class||KTypeListLength< TList >|
Typelists are lists of C++ types of arbitrary length.
They are used to carry type information at compile-time.
- an empty list is of type KDE::NullType (the terminal marker)
- a one-element list with element
Tis of type KTypeList<T, KDE::NullType>.
- a two-element list with elements
Uis of type KTypeList<T, KTypeList<U, KDE::NullType> >.
- an N-Element list with the first element
Tand the remaining elements
Restis of type KTypeList<T, Rest>.
Note that the last element of a typelist is always KDE::NullType. Also note that this is only a convention, it is not enforced by anything. But if these rules are broken, the compile-time algorithms defined for typelists don't work.
To ease the definition of typelists, there are some macros which expand to nested KTypeList definitions. These macros have the form
N is the number of types in the list (e.g. K_TYPELIST_3())
In addition to that, and also as the preferred way, there is the KMakeTypeList template which takes an arbitrary number of type arguments (up to 18) and exports a nested typedef called
Result which equals a KTypeList with the list of provided arguments.
To work with typelists, several compile-time algorithms are provided:
- KTypeListLength: determine the number of elements in a typelist
- KTypeListIndexOf: find a given type in a typelist
For a detailed discussion about typelists, see the book "Modern C++ Design: Generic Programming and Design Patterns Applied" by Andrei Alexandrescu, and/or the Loki Library at http://sourceforge.net/projects/loki-lib/