Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++11 non-type template parameter bundle expansion

Tags:

c++

c++11

g++4.8

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?

like image 692
user3245596 Avatar asked Jan 28 '14 17:01

user3245596


People also ask

Which parameter is allowed for non-type template?

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.

What is the difference between Typename and class in template?

There is no difference between using <typename T> OR <class T> ; i.e. it is a convention used by C++ programmers.

What is template type parameter?

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.

What is a parameter pack C++?

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.


1 Answers

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.

like image 126
bames53 Avatar answered Nov 04 '22 04:11

bames53