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?
Which parameter is legal for non-type template? Explanation: The following are legal for non-type template parameters:integral or enumeration type, Pointer to object or pointer to function, Reference to object or reference to function, Pointer to member.
There is no difference between using <typename T> OR <class T> ; i.e. it is a convention used by C++ programmers.
A template parameter is a special kind of parameter that can be used to pass a type as argument: just like regular function parameters can be used to pass values to a function, template parameters allow to pass also types to a function.
Parameter packs (C++11) A parameter pack can be a type of parameter for templates. Unlike previous parameters, which can only bind to a single argument, a parameter pack can pack multiple parameters into a single parameter by placing an ellipsis to the left of the parameter name.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With