Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Template specialization with variadic templates

Tags:

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?

like image 779
coyotte508 Avatar asked Oct 14 '11 11:10

coyotte508


People also ask

What is the use of 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.

What is Variadic template in C++?

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.

What means variadic?

variadic (not comparable) (computing, mathematics, linguistics) Taking a variable number of arguments; especially, taking arbitrarily many arguments.


1 Answers

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)

like image 85
PlasmaHH Avatar answered Sep 18 '22 04:09

PlasmaHH