template <size_t size, typename ...Params>
void doStuff(Params...) {
}
template <>
void doStuff<size_t(1), int, bool>(int, bool) {
}
int main(int, char**) {
doStuff<1,int,bool>(1, false);
return 0;
}
This doesn't compile, the second doStuff declaration gives me error: template-id ‘doStuff<1u, int, bool>’ for ‘void doStuff(int, bool)’ does not match any template declaration
but it clearly matches the first declaration with variadic template arguments.
How to specialize variadic templates?
With the variadic templates feature, you can define class or function templates that have any number (including zero) of parameters. To achieve this goal, this feature introduces a kind of parameter called parameter pack to represent a list of zero or more parameters for templates.
Variadic templates are class or function templates, that can take any variable(zero or more) number of arguments. In C++, templates can have a fixed number of parameters only that have to be specified at the time of declaration.
variadic (not comparable) (computing, mathematics, linguistics) Taking a variable number of arguments; especially, taking arbitrarily many arguments.
The syntax is correct (afaik, and clang++ accepts it), but your compiler is probably just not up2date yet.
If you use gcc, its variadic template support is quite incomplete, and even very recent svn versions don't support specialization yet (That is just how it is when you use bleeding edge technology, and sadly gcc implemented only a very early incomplete variadic template proposal and since then didn't keep up much, while clang started pretty late, but got pretty complete)
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