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

Loss of rvalue qualifier with variadic template arguments

I'm trying to write a generic factory class with automatic self-registration of types for my application. In order to allow flexibility, this factory has a variadic template parameter for constructor arguments; i.e. it allows either default…
Shmuel Levine
  • 550
  • 5
  • 18
3
votes
3 answers

How to: variadic wrapper function that catches exceptions of input function

I am trying to create a function that I can pass other functions, which will catch any errors, but otherwise simply return the return value of the function. Here's what I've tried: #include using namespace std; int fun(int input) { …
quant
  • 21,507
  • 32
  • 115
  • 211
3
votes
1 answer

Expanding an STL container into a variadic template

To keep things generic and straightforward, say that I have a std::vector of integers, such as: std::vector v; Now, what I am wondering is, is it possible to take n (where n is a constant known at compile time) values from v and pass them to…
Ben H
  • 31
  • 5
3
votes
1 answer

C++11 strange error with templated functions

I have the following code: #include #include #include #include using namespace std; struct Void{ static constexpr int size = 0; }; template class Variadic{ private: …
tower120
  • 5,007
  • 6
  • 40
  • 88
3
votes
2 answers

Creating a C++ std::tuple projection function

I am looking for a projection function for std::tuple. I.e., the function receives a list of integers as template parameters and returns a tuple that only has the values at these indexes. For example, consider I have a tuple…
gexicide
  • 38,535
  • 21
  • 92
  • 152
3
votes
1 answer

Recursive printing of tuple in C++

There are several proposals on how to print a tuple. The snippet below reproduces the answer of Kenny from overloading operator << for std::tuple - possible simplications?. #include #include #include // template…
akim
  • 8,255
  • 3
  • 44
  • 60
3
votes
3 answers

How to fill a vector with typeid's from variadic template arguments

std::vector vec; template void Fill() { vec.push_back(typeid(T1)); // fill the vector with the remaining type ids } I want to fill the vector with the typeids of the template arguments. How…
Appleshell
  • 7,088
  • 6
  • 47
  • 96
3
votes
5 answers

How to get the i-th integer in a integer parameter pack?

How to get the i-th integer in a integer parameter pack? For example template struct A { enum { CONSTANT_0 = Is[0] }; //Assume the sizeof...(Is) > the index requested };
user1899020
  • 13,167
  • 21
  • 79
  • 154
3
votes
2 answers

Why is this Template Class Not Compiling?

So I have the following bit of code: template class Delegate { public: Delegate(Type x) { } }; void Method() { } int main() { Delegate d(&Method); return 0; } My question is: why can't the compiler deduce the…
Will Custode
  • 4,576
  • 3
  • 26
  • 51
3
votes
3 answers

Container of tuples using flat array storage

Is there a C++11 implementation/library publicly available that offers a container of tuples where each tuple element is stored in its own flat container? What I am looking for is something like this struct A { using type = double; }; struct B {…
3
votes
3 answers

Most cpu-efficient way to use std:: algorithms with arguments to a variadic function template?

Say you have a variadic function template which takes a functor and a sequence of homogeneous types, and you want to use std::accumulate to fold the sequence, like so: template do_something(const…
etherice
  • 1,761
  • 15
  • 25
3
votes
3 answers

How do I pass arbitrary member function of ANY class to template in order to resolve its signature?

In my engine, I have simple reflection system filled with classes info at compile time (that is, built around set of templates, that allows me to automate the process of generating metainfo). Consider following example: class Type { //... …
Mateusz Grzejek
  • 11,698
  • 3
  • 32
  • 49
3
votes
1 answer

Workaround for GCC 4.8.1: sorry, unimplemented: mangling argument_pack_select

Consider the following code: #include template Result f(Function func, Types... values) { return std::get<0>(std::make_tuple(func(values)...)); } template int g(const…
Vincent
  • 57,703
  • 61
  • 205
  • 388
3
votes
1 answer

How to implement recursive "using"/extract template parameters

So someone asked a question then deleted it, but I found it an interesting challenge. They had this weird type, and had run into the problem that Concat and Range were castable to Sequences but were not Sequences (for obvious…
IdeaHat
  • 7,641
  • 1
  • 22
  • 53
3
votes
3 answers

Variadic variable initialization for variadic template

I have a templated class A in which I want to call a templated function from another class B the header looks like : template class A { public: A(); void get(type_X params); private: B b_; }; and the .hxx…
Thibaut
  • 133
  • 1
  • 10