CeePlusPlus techniques that yield compile time solutions for problems usually determined at runtime:
- the unrolling of a loop
- function calculations (cos, sin, ...)
- presence of member functions for a given object
Implementations:
- Alexandrescu's Loki
TinyTTL
Boost MPL
Template metaprogramming stores information used for compile time calculations in the type system. Partial template specicialization handles special cases. Metaprograms use metafunctions and metavariables:
- TemplateMetavariables
- TemplateMetafunctionIdentity
- TemplateMetafunctionIf
- TemplateMetafunctionAnd
- TemplateMetafunctionHasFunction
Interestingly, the C++ standard allows escaping template closures and HigherOrder templates. This makes compiling a small LambdaCalculus -like language to C++ Templates nearly trivial. Unfortunately, the standard-prescribed maximal recursion depth is rather low (13 levels, I believe), but most compilers have a much larger limit, usually in the range of several hundred levels.
CategoryCppTemplates CategoryMetaprogramming