Defining members of explicit specializations
13.9.4 [temp.expl.spec]
Mike Miller

Created on 2005-10-01.00:00:00 last changed 96 months ago


Date: 2011-03-15.00:00:00

[Voted into the WP at the March, 2011 meeting as part of paper N3262.]

Date: 2010-06-15.00:00:00

Note (June, 2010):

Because the survey of implementations on which the CWG relied in reaching this resolution is quite old, a new survey of current practice is needed.

Date: 2010-02-15.00:00:00

Proposed resolution (February, 2010) [SUPERSEDED]:

Change 13.9.4 [temp.expl.spec] paragraph 5 as follows:

...The definition of an explicitly specialized class is unrelated to the definition of a generated specialization. That is, its members need not have the same names, types, etc. as the members of a generated specialization. Definitions of members of an explicitly specialized class are defined in the same manner as members of normal classes, and not using the syntax for explicit specialization using the same template<> prefix(es) as the explicitly specialized class. [Example:

    template<class T> struct A {
      void f(T) { /* ... */ }
      struct B { /* ... */ };
      template<class U> struct C { /* ... */ };
    template<> struct A<int> {
      void f(int);
      struct B;
      template<class U> struct C;
    void h() {
      A<int> a;
      a.f(16); // A<int>::f must be defined somewhere
    // explicit specialization syntax not used for a member of
    // explicitly specialized class template specialization
    // members of explicitly specialized classes are defined using
    //the same syntax as the explicitly specialized class:
    template<> void A<int>::f(int) { /* ... */ }
    template<> struct A<int>::B { /* ... */ };
    template<> template<class T> struct A<int>::C { /* ... */ };

end example]

Date: 2005-10-15.00:00:00

Notes from the October, 2005 meeting:

The CWG felt that the best approach, balancing consistency with implementation issues and existing practice, would be to require that template<> be used when defining members of all explicit specializations, including those currently covered by 13.9.4 [temp.expl.spec] paragraph 4.

Date: 2005-10-01.00:00:00

The Standard does not fully describe the syntax to be used when a member of an explicitly-specialized member class or member class template is defined in namespace scope. 13.9.4 [temp.expl.spec] paragraph 4 says that the “explicit specialization syntax” (presumably referring to “template<>”) is not used in defining a member of an explicit specialization when a class template is explicitly specialized as a class. However, nothing is said anywhere about how to define a member of a specialization when:

  1. the entity being specialized is a class (member of a template class) rather than a class template.

  2. the result of the specialization is a class template rather than a class (cf 13.9.4 [temp.expl.spec] paragraph 18, which describes this case as a “member template that... remain[s] unspecialized”).

(See paper J16/05-0148 = WG21 N1888 for further details, including a survey of existing implementation practice.)

Date User Action Args
2014-03-03 00:00:00adminsetstatus: fdis -> c++11
2011-04-10 00:00:00adminsetmessages: + msg3399
2011-04-10 00:00:00adminsetstatus: review -> fdis
2010-08-23 00:00:00adminsetmessages: + msg2834
2010-02-16 00:00:00adminsetmessages: + msg2563
2010-02-16 00:00:00adminsetstatus: drafting -> review
2005-10-22 00:00:00adminsetmessages: + msg1259
2005-10-01 00:00:00admincreate