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?
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.
I guess as a workaround you can do this:
template <size_t... Indices> void wrapper() {
constexpr int x[] = {Indices...};
testFunc(x[0], x[1]);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.