lundi 28 novembre 2016

if template alias declaration resolve to a new family of types?

considering following code :

what happens when we use a template alias, as in X? Is the specialization X still used, since Z is an alias for Y? what happens when we use a template alias , if template alias declaration resolve to a new family of types ?

#include <iostream>

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;
}

output :21

Aucun commentaire:

Enregistrer un commentaire