Allows customizing class and variable (since C++14) templates for a given category of template arguments.
where class-head-name identifies the name of a previously declared class template and declarator identifies the name of a previously declared variable template (since C++14) . This declaration must be in the same namespace or, for member templates, class scope as the primary template definition which it specializes .
For example,
Examples of partial specializations in the standard library include std::unique_ptr , which has a partial specialization for array types.
The following restrictions apply to the argument-list of a partial template specialization:
Moreover, the specialization has to be more specialized than the primary template
Partial template specializations are not found by name lookup. Only if the primary template is found by name lookup, its partial specializations are considered. In particular, a using declaration that makes a primary template visible, makes partial specializations visible as well:
When a class or variable (since C++14) template is instantiated, and there are partial specializations available, the compiler has to decide if the primary template is going to be used or one of its partial specializations.
Informally "A is more specialized than B" means "A accepts a subset of the types that B accepts".
Formally, to establish more-specialized-than relationship between partial specializations, each is first converted to a fictitious function template as follows:
The function templates are then ranked as if for function template overloading.
The template parameter list and the template argument list of a member of a partial specialization must match the parameter list and the argument list of the partial specialization.
Just like with members of primary templates, they only need to be defined if used in the program.
Members of partial specializations are not related to the members of the primary template.
Explicit (full) specialization of a member of a partial specialization is declared the same way as an explicit specialization of the primary template.
If a primary template is a member of another class template, its partial specializations are members of the enclosing class template. If the enclosing template is instantiated, the declaration of each member partial specialization is instantiated as well (the same way declarations, but not definitions, of all other members of a template are instantiated).
If the primary member template is explicitly (fully) specialized for a given (implicit) specialization of the enclosing class template, the partial specializations of the member template are ignored for this specialization of the enclosing class template.
If a partial specialization of the member template is explicitly specialized for a given (implicit) specialization of the enclosing class template, the primary member template and its other partial specializations are still considered for this specialization of the enclosing class template.
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.