c – 为什么课堂上的部分专业化形式良好?

根据[temp.class.spec] 5 /(强调我的)

A class template partial specialization may be declared or redeclared
in any namespace scope in which the corresponding primary template may
be defined

这表明部分特化(就像显式特化的情况一样)必须出现在命名空间范围内.这实际上是通过段落下面的例子证实的:

template<class T> struct A {
     struct C {
          template<class T2> struct B { };
     };
};
// partial specialization of A<T>::C::B<T2>
template<class T> template<class T2>
     struct A<T>::C::B<T2*> { };

//...
A<short>::C::B<int*> absip; // uses partial specialization

另一方面,C++ Standard Core Language Active Issues No 727示例表明,类内部分专业化很好:

struct A {
  template<class T> struct B;
  template <class T> struct B<T*> { }; // well-formed
  template <> struct B<int*> { }; // ill-formed
};

我确定核心问题文件在这里是正确的,但找不到适当的参考来证实.你能帮助我吗?

最佳答案 意图是它有效 – 见
N4090

Following a brief discussion of DR 17557 and DR 7278 in Issaquah 2014, and based on discussion on the core-reflector91011, it seems as if Core is converging on the following rules for member templates and their specializations: Partial specializations and explicit specializations can be first
declared at
either innermost-enclosing-class scope or enclosing
namespace scope (recognizing that explicitly declaring specializations
does not constitute adding members to a class and hence can be done
after the closing brace).

7 07001
8 07002
9 07003(24033, 24290, 24309, 24368)

10 07004(24731, 24732, 24736, 24738)

11 07005 (25168­-25179)

我提出了一个核心问题,因为我觉得目前的措辞不够明确;您引用的段落可以解释为禁止类内部分特化.

点赞