A template is a C++ entity that defines one of the following:
- a family of classes (class template), which may be nested classes
- a family of functions (function template), which may be member functions
- an alias to a family of types (alias template) (since C++11)
- a family of variables (variable template) (since C++14)
Templates are parametrized by one or more template parameters, of three kinds: type template parameters, non-type template parameters, and template template parameters.
When template arguments are provided or, for function templates only, deduced, they are substituted for the template parameters to obtain a specialization of the template, that is, a specific type or a specific function lvalue. Specializations may also be provided explicitly: full specializations are allowed for both class and function templates, partial specializations are only allowed for class templates.
When a class template specialization is referenced in context that requires a complete object type, or when a function template specialization is referenced in context that requires a function definition to exist, the template is instantiated (the code for it is actually compiled), unless the template was already explicitly specialized or explicitly instantiated. Instantiation of a class template doesn't instantiate any of its member functions unless they are also used. At link time, identical instantiations generated by different translation units are merged.
The definition of a template must be visible at the point of implicit instantiation, which is why template libraries typically provide all template definitions in the headers (e.g. most boost libraries are header-only)
|This section is incomplete|
Reason: core syntax, template parameters, and instantiations, take content common between class_template and function_template