It's valid and this appears to be a bug in gcc's variadic templates implementation. I searched a bit on the gcc bugzilla page and did not find any reports of this issue.
C++11 non-type template parameter bundle expansion
Question
While working with C++11 template parameter bundles, I came up with the code below:
#include <cstdio>
static void testFunc(int i1, int i2) {
printf("testFunc(%d, %d)\n", i1, i2);
}
template <size_t... Indices> void wrapper() {
testFunc(Indices...);
}
int main(int argc, char *argv[]) {
wrapper<1, 2>();
return 0;
}
An attempt to compile this with g++4.8.2 resulted in a
"too few arguments to function ‘void testFunc(int, int)’"
error.
Is this no valid C++ or does g++ just not yet implement this kind of non-type template parameter bundle usage?
Solution
OTHER TIPS
I guess as a workaround you can do this:
template <size_t... Indices> void wrapper() {
constexpr int x[] = {Indices...};
testFunc(x[0], x[1]);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow