Questions tagged [variadic-templates]

Variadic templates are templates that take a variable number of parameters.

Some programming languages, like D and C++ since with the C++11 standard, support templates that take a variable number of parameters. Variadic templates are useful in a number of situations, for example, defining type-safe heterogeneous containers such as tuples and expanded metaprogramming library facilities.

http://en.wikipedia.org/wiki/Variadic_templates

3928 questions
18
votes
2 answers

How do I use variadic perfect forwarding into a lambda?

I have a working function template that calls a lambda. I would like to generalize this function template to take variadic arguments and forward them perfectly into the lambda, but I am having trouble getting this code to compile. I am using gcc…
kfmfe04
  • 14,936
  • 14
  • 74
  • 140
17
votes
2 answers

How to detect the first and the last argument in the variadic templates?

How to detect the first and the last argument in the variadic templates? For the 1st argument it is easy (just compare sizeof...(T) with 0), but is there a way to detect the last element? The example : #include #include…
BЈовић
  • 62,405
  • 41
  • 173
  • 273
17
votes
1 answer

Comparing variadic templates

If I have two variadic template arguments, A and B, how can I ensure at compile-time that the types of all of the members of A are also the types of a subset of B (in the same order)? Contrived example: template struct Foo { …
Sydius
  • 13,567
  • 17
  • 59
  • 76
17
votes
2 answers

How do variadic type template parameters and non-type template parameters of the template template parameter of a nested class constrain each other?

Consider the following structure: S is a class template with a variadic pack of template type parameters ...Ts. The class contains a nested class template N, which has a single template template parameter C. C itself is templated with a variadic…
cigien
  • 57,834
  • 11
  • 73
  • 112
17
votes
3 answers

Template specialization for an empty parameter pack

I have a variadic template function which calls itself to determine the largest number in a list (constituted by the templatized arguments). I am trying to make a specialization for when the parameter pack is empty so I can just return the number at…
Seth Carnegie
  • 73,875
  • 22
  • 181
  • 249
17
votes
1 answer

g++ and clang++ different behaviour deducing variadic template `auto` values

Another "who's right between g++ and clang++?" This time I'm convinced it's a g++ bug, but I ask for a confirm from standard gurus. Given the following code template