C++ template specialization rules mentioned specialization has to be more specialized than the primary template. Following #1 code snippet causes compilation error which says the second line is not more specialized, but the last snippet (#2) works which looks very close to #1. Both code snippets specialized int N as 0, so why the first snippet is complained as "not more specialized"?
// #1
template<int N, typename T1, typename... Ts> struct B;
template<typename... Ts> struct B<0, Ts...> { }; // Error: not more specialized
// #2
template<int N, typename T1, typename... Ts> struct B;
template<typename T, typename... Ts> struct B<0, T, Ts...> { }; // this works
For more specialized:
Informally "A is more specialized than B" means "A accepts a subset of the types that B accepts".
Whatever types the specialization could accept are supposed to be subset of types the primary template could accept. But for B<0>, it could be accepted by the specialization only, while the primary template can't, because the template parameter T1 is essential.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With