1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
This section serves two purposes. It illustrates capabilities of the various
template meta-programming techniques, which can be used as a source of
inspiration when developing your own templates; and it offers a concrete
example, illustrating some of the power offered by these techniques.
This section itself was inspired by Andrei Alexandrescu's (2001) book
hi(Alexandrescu, A.)
bf(Modern C++ design). It diverts from Alexandrescu's book in its use of
variadic templates which were not yet available when he wrote his book. Even
so, the algorithms used by Alexandrescu are still useful when using variadic
templates.
bf(C++) offers the link(tuple)(TUPLES) to store and retrieve
values of multiple types. Here the focus is merely on processing types. A
simple struct tt(TypeList) is going to be used as our working horse for the
upcoming subsections. Here is its definition:
verbinclude(//TYPELIST examples/typelist.h)
A typelist allows us to store any number of types. Here is an example
storing the three types tt(char, short, int) in a tt(TypeList):
verb( TypeList<char, short, int>)
|