0

Assume the following example

using namespace std;
template <template <typename> class>
struct X 
{
   X() 
   { 
      std::cout << "1"; 
   }
};

template <typename>
struct Y {};

template <typename T>
using Z = Y<T>;

 template <>
 struct X<Y> 
 {
   X() 
   { 
      std::cout << "2"; 
    }
 };

 int main() 
 {
   X<Y> x1;
   X<Z> x2;
 }

The expression X<Y> x1 it is clear that is use the specialization that prints "2"

The second one is strange. Doing analysis the X<Z> is translated to X< Y < T > >. I expect to print "1" . But running the code this prints "2". Which rule is applied in the second one?

max66
  • 65,235
  • 10
  • 71
  • 111
getsoubl
  • 808
  • 10
  • 25
  • If it were translated to `X< Y < T > >`, you'd get an error because `T` is undefined (and another error because `Y` is not a template (as required by `X`), it's a class). – melpomene Aug 22 '18 at 20:54

1 Answers1

0

The second one is strange. Doing analysis the X<Z> is translated to X< Y < T > >. I expect to print "1" . But running the code this prints "2".

No.

You have that Z<T> is defined as Y<T> so Y and Z are the same thing.

And isn't true that X<Z> is translated to X<Y<T>> (and X<Y<T>> can't match because Y<T> is a type where X accept only template-template arguments).

max66
  • 65,235
  • 10
  • 71
  • 111