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

How can I create a typedef for the first parameter of a parameter pack

How can I get access to the individual items in a parameter pack? Given the following: template struct X {}; template struct X { // how can I create a typedef for the first parameter // basically…
bjackfly
  • 3,236
  • 2
  • 25
  • 38
3
votes
1 answer

how to assing multiple std::tuple_element as function arguments using variadic size_t templates

I want to create a function that changes multiple values inside a tuple with one call. template class EventN { public: std::tuple mArgs; EventN(Args... args) : mArgs(args) {} EventN() {} template void…
Gasim
  • 7,615
  • 14
  • 64
  • 131
3
votes
2 answers

std::function like delegate template class

Hi I am trying to write a delegate class that can take a template argument similar to a standard function signature and create a delegate for a member function pointer as shown below in the main. The code may be oversimplified but that is what I was…
bjackfly
  • 3,236
  • 2
  • 25
  • 38
3
votes
2 answers

C++ variadic templates and evaluation order

I have the following code: lib.hxx: template R Lib::extract_call(lua_State* L, R(C::*method)(Args...)) { return static_cast(this)->*method(extract_data(L)...); } lib.cc: template…
Sylomex
  • 33
  • 4
3
votes
3 answers

How to derive from a nested class of a variadic template argument?

Given the following two structs, one could derive from both nested 'Nested' classes, and call foo() and bar() from the derived object: struct WithNested1 { template struct Nested { void foo(); }; }; struct WithNested2 { …
CuriousGeorge
  • 7,120
  • 6
  • 42
  • 74
3
votes
3 answers

how should I call all functions in a variadic parameter pack if the function return type is void?

I have a parameter pack full of default constructable and then callable objects (like the ExampleFunctor) and want to call all of them in order (left to right). If the return type is anything besides void I can use an initializer list to do…
odinthenerd
  • 5,422
  • 1
  • 32
  • 61
3
votes
2 answers

Get variadic template variadic template parameter variadic parameters

Yes. Let's say I have a simple variadic struct that holds a typedef: template struct TupleTypeHolder { using TupleType = std::tuple; }; I want to pass TupleTypeHolder as a template parameter to another…
Vittorio Romeo
  • 90,666
  • 33
  • 258
  • 416
3
votes
1 answer

Performance impact of variadic templates

In the latest refactoring round of my code, I replaced a bunch of template classes with fixed number of template arguments with variadic counterparts. I was quite a bit puzzled to find out that a specific performance test case had seen a drop in…
bluescarni
  • 3,937
  • 1
  • 22
  • 33
3
votes
1 answer

variadic template complex inheritance generation

Playing a bit with variadic templates to try and see what could be done with them, I found myself wondering about something: Let's suppose I have a class which can take several other classes as template parameters, each of them have a nested class…
Julien Lopez
  • 1,021
  • 6
  • 14
3
votes
1 answer

C++ variadic template to replace typelist

I would like to utilize variadic templates to replace this below standard typelist code. Also, note, this uses int as the type. I am trying to incorperate strongly typed enums as defined by C++11 so i want to replace the int HEAD with a template…
user355543
  • 149
  • 1
  • 2
  • 5
3
votes
1 answer

expanding parameter pack in templated constructor of templated class

Before I describe the problem I will give you an idea what is the target of my work. I want to have a template which creates a class ( while do this unrolling a typelist recursively) which derives from all given types in a variadic list of…
Klaus
  • 24,205
  • 7
  • 58
  • 113
3
votes
1 answer

Variadic templates expansion recursively for classes and functions

So I've been trying to understand variadic templates a little bit more, My goal was to receive all types, expand them, and print them.. I was able to do it in for a function(found some examples) but I was not able to do it for a class Here I am…
Alon
  • 1,776
  • 13
  • 31
3
votes
1 answer

CRTP + variadic template + extract CRTP subclass parameters

Im currently implementing a generic event class. Event handlers have a sender parameter and a variable number of event args. So the declaration of the event class is as bellow: template class event; To allow…
Manu343726
  • 13,969
  • 4
  • 40
  • 75
3
votes
1 answer

Variadic template to proxy QtConcurrent::run functions

I was hoping to create a variadic template function which sits in front of the QtConcurrent::run functions that does some stuff and then passes the parameters on. QtConcurrent::run is massively overloaded - check out qtconcurrentrun.h Is it…
gremwell
  • 1,419
  • 17
  • 23
3
votes
2 answers

derive class from a tuple

I have an std::tuple given like this: typedef std::tuple tuple_t; Now, I want to transform t3_tuple into a similar tuple: typedef std::tuple< T, T, T > derived_tuple_t; In my case, for example, t1, t2, and t3 are…
Johannes
  • 2,901
  • 5
  • 30
  • 50