Reputation: 1326
Given following code
template<typename T>
struct A{
struct In{};
};
template<typename T>
struct Desc{
};
template<typename X>
struct Desc<typename A<X>::In> {
};
int main(){
Desc<A<int>::In> a;
}
the compiler refuses the Desc specialization with
error: template parameters not used in partial specialization:
error: ‘X’
Same if the struct is defined by
template<>
template<typename X>
struct Desc<typename A<X>::In> {
};
Definition
template<typename X>
template<>
struct Desc<typename A<X>::In> {
};
gives the error
desc.cpp:14:10: error: invalid explicit specialization before ‘>’ token
desc.cpp:14:10: error: enclosing class templates are not explicitly specialized
desc.cpp:15:8: error: template parameters not used in partial specialization:
desc.cpp:15:8: error: ‘X’
Is this a case of "non-deduced context" as here?
Template parameters not used in partial specialization
It would make sense, since there's no guarantee that the inner class is actually a class (we know only that it is a typename, it may be a typedef). Is there then a way to specify it's a real class?
Upvotes: 2
Views: 629
Reputation: 55887
Is there then a way to specify it's a real class
No, there is no way to specify, if you use this type in partial template specialization.
There are only two ways. Specialize Desc
for concrete A
, so,
template<>
struct Desc<typename A<type>::In> { };
or use something like
template<typename T, typename = void>
struct Desc{
};
template<typename X>
struct Desc<X, typename A<X>::In> {
};
or of course specialize for type A<X>
not for A<X>::In
.
Upvotes: 2