Metaprogramming Helpers

The library implements some interfaces in namespace cxxomfort for assisting in metaprogramming, some of those also included in C++11.

  • identity< type >

Given a type type, defines the member type type as type. Useful for avoiding some type reflection traps in C++.

  • enable_if< condition, type >

Given a boolean compile-time condition, if true, defines the member type type as type. See Documentation (external link). This is reflected as std::enable_if.

  • conditional< condition, type1, type2 >

Given a boolean compile-time condition, if true, defines the member type type as type1, otherwise as type2. See Documentation (external link). This is reflected as std::conditional.

  • selection< index, type0, ..., type9 >

Given an unsigned index and a list of types type0, ..., type9, of which only the first is mandatory, this defines the member type type as the index-th type in the list, if given, or cxxomfort::none_tag otherwise.

  • meta_and<...>, meta_or<...>

Given a list of traits Type1, Type2, ....Typen, each with a boolean value member, this is defined as either true_type or false_type depending on the and (&&) or or (||) of the trait values involved.

  • conditional_if<Trait, T1, T2, ...>

Given a Trait taking one template argument, and a list of types T1, T2, ..., it will define the member type as the first of those types for which the given Trait has value==true.


To be added in the near future:

  • static_max, static_min
  • disable_if (as a writing shortcut)
  • is_instantiation_of