C++ Logo

STD-DISCUSSION

Advanced search

Subject: An confusion about the paragraph [temp.expl.spec#18]
From: jim x (xmh970252187_at_[hidden])
Date: 2020-09-28 03:51:24


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. In such an explicit specialization declaration, the keyword
template followed by a template-parameter-list shall be provided instead of
the template<> preceding the explicit specialization declaration of the
member. The types of the template-parameters in the template-parameter-list
shall be the same as those specified in the primary template definition.

````
template <class T1> class A {
  template<class T2> class B {
   template<class T3> void mf1(T3);
    void mf2();
  };
};
template <class Y> template <>
void A<Y>::B<double>::mf2() { } // error: B<double> is specialized but
                                                     // its enclosing class
template A is not
````

Consider the above example, The comment says that the code is ill-formed.
However, I have to say, such a case is not covered by this rule. My reason
is that, please note the bolded wording, that is "class member template",
in this explicit specialization, `mf2` is not a class member *template, *it
just a member of a class template. So, strictly speaking, that's not the
case of this exception. Instead, these cases conform to this exception.
````
template <class Y>
template <>
template<typename T>
void A<Y>::B<double>::mf1() { }
///////// Or
template <>
template <typename U>
template<typename T>
void A<int>::B<U>::mf1() { }
````
Because, in these two cases, the declaration is an explicit specialization
for the class member template `mf1`, and its enclosing class template
`A<Y>` or `B<U>` does not have been specialized.

So, Does this wording exist defective? According to the example below the
paragraph or the first sentence in this paragraph, the wording may be
"except that the declaration shall not explicitly specialize *a class
member* if its enclosing class templates are not explicitly specialized as
well", Right? After this change, whatever the explicit specialization
declaration for `mf1` or for `mf2` will be ill-formed if its enclosing
class templates are unspecialized. If I misread the paragraph, please
point it out.



STD-DISCUSSION list run by std-discussion-owner@lists.isocpp.org

Older Archives on Google Groups