cpp/language/templates

A template is a C++ entity that defines one of the following:
 * a family of classes, which may be
 * a family of functions, which may be

Templates are parameterized by one or more, of three kinds: type template parameters, non-type template parameters, and template template parameters.

When template arguments are provided, or, for  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: are allowed for class and function templates,  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).

template-id
A that names a class template specialization names a class.

A that names an alias template specialization names a type.

A that names a function template specialization names a function.

A is only valid if
 * there are at most as many arguments as there are parameters or a parameter is a template parameter pack,
 * there is an argument for each non-deducible non-pack parameter that does not have a default template-argument,
 * each template-argument matches the corresponding template-parameter,
 * substitution of each template argument into the following template parameters (if any) succeeds, and

An invalid is a compile-time error, unless it names a function template specialization (in which case  may apply).

Two s are same if
 * their s refer to the same template, and
 * their corresponding type template arguments are the same type, and
 * their corresponding non-type template arguments are after conversion to the type of the template parameter, and
 * their corresponding template template arguments refer to the same template.

Two s that are the same refer to the same class, or function.

Templated entity
A templated entity (or, in some sources, "temploid") is any entity that is defined within a template definition. All of the following are templated entities:
 * a class/function template


 * a member of a templated entity (such as a non-template member function of a class template)
 * an enumerator of an enumeration that is a templated entity
 * any entity defined or created within a templated entity: a local class, a local variable, a friend function, etc

For example, in

the function is not a function template, but is still considered to be templated.

A templated function is a function template or a function that is templated.

A templated class is a class template or a class that is templated.