1

Possible Duplicate:
GCC error with variadic templates: “Sorry, unimplemented: cannot expand 'Identifier…' into a fixed-length argument list”

I have this code, and it produces the error message shown in the title:

#include <iostream>

template <int FIRST, int... NEXT>
struct Test {
    static const int VALUE = FIRST + Test<NEXT...>::VALUE;
};

template <int FIRST>
struct Test<FIRST> {
    static const int VALUE = FIRST;
};

int main() {
    std::cout << Test<1, 2, 3>::VALUE << std::endl; // print "6"
    return 0;
}

Is there any simple workaround that will make it compile in GCC without changing what it does?

Community
  • 1
  • 1
mtk358
  • 565
  • 1
  • 7
  • 20
  • I saw that answer, but I don't really understand it (what are all those different classes for, what do they have to do with the original question, and why does it work when the code in the original question didn't?). – mtk358 Mar 22 '12 at 20:46
  • The reason it's a duplicate is because you're getting the error for the same reason as the other question: your version of GCC doesn't implement this use of varadic templates. You must either update it or do without varadic templates. – Nicol Bolas Mar 22 '12 at 23:48
  • 1
    @Nicol: You can still use variadic templates just fine, you just have to work around it and use partial specialization. – Xeo Mar 23 '12 at 02:43

1 Answers1

2

Update GCC.

Xeo
  • 129,499
  • 52
  • 291
  • 397
  • +1'd. Fooling around with Turing-completeness in older versions of GCC is...foolish, especially since this uses '0x features – std''OrgnlDave Mar 22 '12 at 20:43
  • 2
    I'm using the version of GCC that's in Arch Linux's repository (4.6.3). And should I be worried about others not being able to compile my program if i don't work around this? – mtk358 Mar 22 '12 at 20:43