Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why a template alias specialization depends on the context in which it is referred?

Consider this example code:

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
}

V<int>::pt is an alias for pt_type<V<int>>. Nevertheless the fact it is defined depends on the context where it is referred.

Where is it explained in the C++ standard that the substitution of the template parameter by the template argument is performed in the context where is refered the alias specialization?

like image 207
Oliv Avatar asked Mar 07 '23 01:03

Oliv


1 Answers

Nowhere. This is core issue 1554.

The interaction of alias templates and access control is not clear from the current wording of 14.5.7 [temp.alias]. For example:

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

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

struct C {
  foo<B> f;    // Well-formed?
};
like image 114
T.C. Avatar answered Apr 25 '23 07:04

T.C.