Template partial specialisation

Viewed 264

Can somebody explain why are those two specializations indistinguishable to the compiler (gcc 4.5.1 @ ideone)

http://ideone.com/9tNux

template <typename... T> struct S;

template<typename A, typename B, typename... C>
struct S<A, B, C...> {
   int f() {return 1;}
};

template<typename... A, typename... C>
struct S< S<A...>, C...> {
   int f() {return 2;}
};

and when I try to instantiate S<S<a, b>, a, b> o2; compiler complains:

prog.cpp:20:21: error: ambiguous class template instantiation for 'struct S<S<a, b>, a, b>'
prog.cpp:6:22: error: candidates are: struct S<A, B, C ...>
prog.cpp:11:33: error:                 struct S<S<A ...>, C ...>
prog.cpp:20:21: error: aggregate 'S<S<a, b>, a, b> o2' has incomplete type and cannot be defined

And when the last specialization is changed to:

template<typename... A, typename B, typename... C>
struct S< S<A...>, B, C...> {
   int f() {return 2;}
}

everything works fine.

2 Answers
Related