[temp.class.spec.mfunc] (original) (raw)

13 Templates [temp]

13.7 Template declarations [temp.decls]

13.7.6 Class template partial specializations [temp.class.spec]

13.7.6.4 Members of class template specializations [temp.class.spec.mfunc]

The template parameter list of a member of a class template partial specialization shall match the template parameter list of the class template partial specialization.

The template argument list of a member of a class template partial specialization shall match the template argument list of the class template partial specialization.

A class template partial specialization is a distinct template.

The members of the class template partial specialization are unrelated to the members of the primary template.

Class template partial specialization members that are used in a way that requires a definition shall be defined; the definitions of members of the primary template are never used as definitions for members of a class template partial specialization.

An explicit specialization of a member of a class template partial specialization is declared in the same way as an explicit specialization of the primary template.

[Example 1: template<class T, int I> struct A { void f();};template<class T, int I> void A<T,I>::f() { } template<class T> struct A<T,2> { void f();void g();void h();};template<class T> void A<T,2>::g() { } template<> void A<char,2>::h() { } int main() { A<char,0> a0; A<char,2> a2; a0.f(); a2.g(); a2.h(); a2.f(); } — _end example_]

If a member template of a class template is partially specialized, the member template partial specializations are member templates of the enclosing class template; if the enclosing class template is instantiated ([temp.inst], [temp.explicit]), a declaration for every member template partial specialization is also instantiated as part of creating the members of the class template specialization.

If the primary member template is explicitly 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.

[Example 2: template<class T> struct A { template<class T2> struct B {}; template<class T2> struct B<T2*> {}; };template<> template<class T2> struct A<short>::B {}; A<char>::B<int*> abcip; A<short>::B<int*> absip; A<char>::B<int> abci; — _end example_]