为什么模板别名专门化取决于它所引用的上下文?

Oli*_*liv 4 c++ alias templates language-lawyer template-aliases

考虑这个示例代码:

template <class T>
using pt_type = typename T::type;

template <class T>
class V {
  using type = int;
  public:
  using pt = pt_type<V>;
};

void g() {
  V<int>::pt a; // Does compile
  pt_type<V<int>> b; // Does not compile
}
Run Code Online (Sandbox Code Playgroud)

V<int>::pt是别名pt_type<V<int>>.然而,它被定义的事实取决于它被引用的背景.

C++标准中解释的是,模板参数替换模板参数是在提到别名特化的上下文中执行的?

T.C*_*.C. 9

无处.这是核心问题1554.

别名模板和访问控制的交互在14.5.7 [temp.alias]的当前措辞中并不清楚.例如:

template <class T> using foo = typename T::foo;

class B {
  typedef int foo;
  friend struct C;
};

struct C {
  foo<B> f;    // Well-formed?
};
Run Code Online (Sandbox Code Playgroud)