Why does the specialization of a template template depend on the context in which it is passed?

Consider this code example:

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; //Do compile
  pt_type<V<int>> b; //Do not compile
  }

V<int>::ptis an alias for pt_type<V<int>>. However, the fact that it is defined depends on the context in which it is mentioned.

Where is it explained in the C ++ standard that substituting a template parameter with a template argument is done in the context where the specialization of the alias is mentioned?

+4
source share
3 answers

Nowhere. This is the main problem of 1554 .

The interaction of alias patterns and access control is not clear from the current version 14.5.7 [temp.alias]. For instance:

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

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

struct C {
  foo<B> f;    // Well-formed?
};
+9
source

using pt_type = typename T::type; cannot access type type V ::.

:

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

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

void g()
{
    V<int>::pt a; //Do compile
    pt_type<V<int>> b; //Do not compile
}
-1

In V :: pt, you get access to your own type, and you can do it, but the quotient makes it impossible in the second case. Thus, V :: pt creates the initialization pt_type, passing your private type int. But in the second case, you are trying directly, and it doesn’t work,

-1
source

Source: https://habr.com/ru/post/1692737/


All Articles