IT lexicon › Programming › C++ templates

C++ templates

Programming På svenska → Updated: 2026-05-26

C++'s generic programming mechanism. Write code parameterized by types: template<typename T> class Vector { T data; ... };. Bjarne Stroustrup, 1990.

Notoriously complicated error messages ("template error vomit"). SFINAE (Substitution Failure Is Not An Error) is the trick for partial specialization. Template metaprogramming = compute values at compile time (classic: Factorial<5>::value). Concepts (C++20) standardize template constraints → much cleaner error messages. Monomorphization-based (compiles different code per instantiated type) ⇒ fast runtime but larger binaries. STL (Standard Template Library) is built entirely on templates: std::vector, std::map, <algorithm>.

← Back to the lexicon