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
3
votes
2 answers

Templating boost::bind to automatically handle multiple arguments for member function

I have a class with an "Attach" function that accepts a function object and stores it into a collection. The class itself is templated on the function signature. Something like this: template class Event { public: void…
Robinson
  • 9,666
  • 16
  • 71
  • 115
3
votes
5 answers

C++ variadic template arguments method to pass to a method without variadic arguments

I have the following question, I really can't compile from all the questions and articles researched: In C++, is it possible to have a method with variadic template arguments that specify types of arguments (as a meta-description type for parameters…
mike
  • 408
  • 5
  • 18
3
votes
3 answers

Gaining access to the tuple by string template param

A standard tuple in C++ 11 allows access by the integer template param like this: tuple test; test.get<1>(); but if I want get access by the string template param: test.get<"first">() how can I implement it?
COUNTERKILL
  • 173
  • 10
3
votes
2 answers

Template function binding variadic number of tuple's elements to another function as arguments

Is there any way in c++11/14 to write variadic template function like this: template std::function bindArgumentsFromTuple (std::function
attuda
  • 33
  • 3
3
votes
1 answer

multiple template parameter lists are not allowed

What is the issue here? struct fbe { char *fbtName; template T(*funcptr)(T, vT... ); }; And what is the difference that made it compile when writing like this? template struct fbe…
kar
  • 495
  • 1
  • 8
  • 19
3
votes
2 answers

Variadic template unpacking arguments in typedef

Given the following C++ typedef expression template struct BoolType : std::true_type {}; template <> struct BoolType< false > : std::false_type {}; typedef BoolType< ArgResolver< Arg1 >::IsResolvable::value && ArgResolver< Arg2…
Stefano
  • 3,213
  • 9
  • 60
  • 101
3
votes
2 answers

Backward variadic template

I want to write a template function that does this (pseudo-code): shift(T& a,T& b,T& c,...,T& y,const T& z) { a = b; b = c; ... y = z; } My attempt involved putting the variadic argument as the first argument as follows: template
SU3
  • 5,064
  • 3
  • 35
  • 66
3
votes
1 answer

Empty parameter pack expansion different to manual empty parameter pack

It seems that GCC treats expanding an empty parameter pack A into another parameter pack B differently than manually entering an empty parameter pack B. Example: void baz(); void baz(int); template void bar(R…
Simple
  • 13,992
  • 2
  • 47
  • 47
3
votes
1 answer

Variadic templates give errors on more than one parameter

I am trying out the code from http://florianjw.de/en/variadic_templates.html: #include #include #include #include template void sequential_foreach(Fun f, const Ts&... args)…
Patryk
  • 22,602
  • 44
  • 128
  • 244
3
votes
3 answers

Passing multiple functions to for each algorithm

I would like to ask if it's possible to define for each algorithm (like in STL) that would take multiple functions as input arguments and evaluate them in left to right order? template void for_each(Iterator…
Alexander Bily
  • 925
  • 5
  • 18
3
votes
1 answer

Template variadic argument referenced from another argument

I'm in trouble for the way I should reference arguments in a template (honestly, I strongly suspect that it's not possible to achieve what I'd like to do). It follows an example of what I'd like to do (of course, this is not syntactically legal, the…
skypjack
  • 49,335
  • 19
  • 95
  • 187
3
votes
2 answers

Variadic Tuple Order changes after Unpacking depending on Datatypes

The code should call back a function by extracting arguments from a string. However, the order changes as follows: (Visual Studio 2013 AND 2015! express) "1 2 3 4" int, double, string, int -> 3 2 4 1 "1 2 3 4" int, double, float, int -> 4 3 2…
Marco Polo
  • 91
  • 5
3
votes
0 answers

Initializer list in variadic template

The answer to this question says that braced-init lists cannot be used in template arguments. What if there is an explicit initializer list specialization? I am trying to write a reduce-like function that would accept the following syntax: f(1, {2},…
3
votes
2 answers

Variadic Template Functions

I want to be able to pass a variadic number of function pointers to a template function, say foo. The example below shows what I have so far however it does not compile when I actually pass more than one template argument: #include…
Reza Toghraee
  • 1,603
  • 1
  • 14
  • 21
3
votes
4 answers

C++ templates std::tuple to void* and back

I'm trying to make a resource manager using C++11 and variadic templates. The question is how to store std::tuple to collection and get it back? I've tried to store it to void* in this example (trying not to use boost::any here). Every time I'm…
Zulis
  • 83
  • 2
  • 8