Reputation: 111
I am considering Class1, Class2, Class3
.
Class2
and Class3
have a partial specialisation with int
, so they are identical in their definition.
On the other hand, Class1
has a specialisation for Class3<T>
and for a general template template with only one argument, i.e. Unary<T>
. So Class1
has no specialisation for Class2<T>
.
It happens that Class1 <Class3<T>>::type
is actually Class3<T>
. Indeed I explicitly wrote the specialisation. However, the compiler says Class1 <Class2<T>>::type
it is not defined. But I defined the specialisation for a the template template case, Class1<Unary<T>>
. Why is the compiler not recognising it? How can I make the compiler choose the most specialised case (Class1 <Class3<T>>::type
), if it exists, and, if does not, the template template case (Class1<Unary<T>>
)? Thank you
template<typename...T>
class Class1;
template<typename...T>
class Class2;
template<typename...T>
class Class3;
template<>
class Class2<int>
{};
template<>
class Class3<int>
{};
template<typename T>
class Class1<Class3<T>>
{
public:
using type=Class3<T>;
};
template<template<class> class Unary, typename T>
class Class1<Unary<T>>
{
public:
using type=Unary<T>;
};
Upvotes: 2
Views: 43
Reputation: 10315
Before C++17 such template:
template<template<class> class Unary, typename T>
class Class1<Unary<T>>
should not mach with variadic templates. Same for templates with defaulted arguments (check this with std::vector
for example) - Template template parameter and default values. It was a defect in standard and fix came in C++17
Upvotes: 1