Tools for Template Metaprogramming

[Some other info on metaprogramming can be fond at the Blitz++ pages.]

The file meta.h in the more library repository defines a set of algorithms for types. By convention, type-functions ends with an underscore. Each type-function has at least one (usually no more) public typedef, eval, which gives the result-type of the operation. The constructs (all template arguments are types):

nulltype    // A type analog to false or NULL (or nil in Lisp)
truetype    // Analog to true
typepair<T, U>  // Used to create lists

if_<Cond, Positive, Negative>
not_<Cond>
equal_<T, U>
equiv_<T, U>
or_<T1, T2, ..., Tn>   // n <= 6
and_<T, U>
xor_<T, U>

append_<List, T>       // appends an element to the end of a list
concat_<List1, List2>
tree_to_list_<Tree>    // converts a tree of typepairs to a list

list_<T1, T2, ..., Tn> // n <= 7

typeassert_<T>

is_a_<T, U>            // is U a base class of T?
is_in_<T, List>        // is T in List?
is_pointer_<T>         // is T a pointer type?
is_class_<T>           // is T a class type?  (Doesn't work for enum.)

Examples:

list_<short, int, long>::eval
   // generates typepair<short, typepair<int, typepair<long, nulltype> > >
equal_<int, short>::eval                 // gives nulltype
equal_< vector<int>, vector<int> >::eval // gives vector<int>
equal_<nulltype, nulltype>               // gives truetype
equiv_<int, short>::eval                 // gives truetype
equiv_<int, nulltype>::eval              // gives nulltype
equiv_<nulltype, nulltype>::eval         // gives truetype

Petter Urkedal
Last modified: Wed Mar 10 13:50:12 CET 1999