3
votes

In the current draft of the C++ standard, the paragraph [temp.expl.spec]p.18 says:

A specialization of a member function template, member class template, or static data member template of a non-specialized class template is itself a template.

However, the above paragraph temp.expl.spec]p.17 states (my emphasis):

In an explicit specialization declaration for a member of a class template or a member template that appears in namespace scope, the member template and some of its enclosing class templates may remain unspecialized, except that the declaration shall not explicitly specialize a class member template if its enclosing class templates are not explicitly specialized as well. [...]

Therefore, it should be impossible to explicitly specialize a member template without specializing its enclosing class template, so [temp.expl.spec]p.18 is wrong. I highlighted the word explicitly because [temp.expl.spec]p.18 says "A specialization [...]". Specialization can have a lot of meanings, one of which could be explicit specialization.

I checked and [temp.expl.spec]p.18 appeared in the standard before [temp.expl.spec]p.17. For example, in the 1996 version of the standard [temp.expl.spec]p.18 is present while [temp.expl.spec]p.17 is not.

What is the original intended meaning of [temp.expl.spec]p.18?

Thank you.

1
Probably just that it still counts as a template - specialization a member function template doesn't just turn it into a non-template function.Barry
But what type of specialization is the paragraph referring to? Explicit specialization? Or the specialization which comes from implicit instantiation? Because if the answer is the former, I don't think the paragraph is correct in the current version of the standard.user42768
Any specialization. The two paragraphs do not strike me as related. 17 provides some restrictions on specializations, 18 just says that specializations of member templates are still templates.Barry
Paragraph 17 says that you cannot explicitly specialize a member template without specializing its enclosing class template. Therefore there cannot be any explicit "specialization of a member [...] of a non-specialized class template [...]".user42768
Note: these points are 16 and 17 in the C++17 standard (N4659); the latest draft changed the numberingM.M

1 Answers

2
votes

There can be partial specialization of a member class template of a non-specialized class template.

Your point 17 prohibits full specialization of such a member; and point 18 clarifies that the partial specialization in this case is still a template.

The terminology "explicitly specialize" means fully specialize, and excludes partial specialization.

template<typename T>
struct A
{
     template<typename U, typename V>
     struct B
     { 
         void f() {}
     };
};

// OK: Partially specialize A<T>::B. This is a template
template<typename T>
template<typename U>
struct A<T>::B<U, int>   
{
    void g() {}
};