20
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?

coyotte508
  • 9,175
  • 6
  • 44
  • 63

1 Answers1

12

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)

PlasmaHH
  • 15,673
  • 5
  • 44
  • 57
  • I use gcc 4.5.2. Thanks for your answer (I'm using template overloading instead now). – coyotte508 Oct 14 '11 at 12:23
  • Alternatively you could wrap the function in a `template<..> struct Do { static void Stuff(..) { } };`. – Kerrek SB Oct 14 '11 at 12:24
  • @coyotte508: That is probably the best for function templates, some people even say that function template specialization is always wrong... – PlasmaHH Oct 14 '11 at 12:25