2

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?

Community
  • 1
  • 1
Fabio Dalla Libera
  • 1,297
  • 1
  • 10
  • 24
  • 1
    I'm afraid that is the case. Can't you just specialise for `A`? Inside the specialisation you can use `A::In` everywhere, of course. – Gorpik Aug 23 '12 at 12:12

1 Answers1

2

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.

ForEveR
  • 55,233
  • 2
  • 119
  • 133