Template metaprogramming is a family of techniques to create new types and compute values at compile time. C++ templates are Turing complete if there are no limits to the amount of recursive instantiations and the number of allowed state variables. Erwin Unruh was the first to demonstrate template metaprogramming at a committee meeting by instructing the compiler to print out prime numbers in error messages. The standard recommends an implementation support at least 1024 levels of recursive instantiation, and infinite recursion in template instantiations is undefined behavior.
Reason: Techniques (specializations, SFINAE, ADL, index sequences, folds, constxpr if, etc)
Reason: Terms (traits, typelists, metafunctions, etc)
Reason: Libraries Boost.MPL / Boost.Mp11 / Metal / Kvasir.MPL / Boost.Hana / etc (maybe even Loki from the dark ages)
Reason: History maybe
External links
| 1. | David Vandevoorde, Nicolai M. Josuttis, Douglas Gregor (2017), C++ Templates - The Complete Guide, 2nd Edition. |
| 2. | Wikibook: Template Meta-Programming. |
| 3. | Wikipedia: Template Meta-Programming. |
Content from this page on cppreference.com, licensed under CC-BY-SA 3.0 and GFDL. Modified: restyled, site navigation removed, code windows added. Offline snapshot of 9 February 2025.