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
1 answer

What's the most efficient tail recursive prime verification function known?

I was experimenting with meta programming to this point: // compiled on Ubuntu 13.04 with: // clang++ -O3 -ftemplate-depth-8192 -fconstexpr-depth=4096 -std=c++11 -stdlib=libc++ -lcxxrt -ldl compile-time-primes.cpp -o compile-time-primes // assembly…
3
votes
1 answer

Expansion of a variadic template function causes segmentation fault

I am studying the new C++11 feature about the Variadic Templates, so I wrote a fun template function: template void fun(T& a) //Base to stop the recursion { std::cout << a; }; template void fun(Types... args) { …
Avraam Mavridis
  • 8,698
  • 19
  • 79
  • 133
3
votes
3 answers

How to extract the argument list in variadic templates for n-dimensional array

I have a template class with the following specification: template class Array; And say it can be used as follows: // Define a 2X3X4 array of integers. Elements are uninitialized. Array a, b; Array
footy
  • 5,803
  • 13
  • 48
  • 96
3
votes
1 answer

Extern template with variadic arguments doesn't compile

I try to create a extern template with variadic arguments like: extern template void log( XS... xs ); But gcc 7.2 doesn't compile it, and show the error: error: expected unqualified-id before ‘<’ token I check the gcc status in…
Zhen
  • 4,171
  • 5
  • 38
  • 57
3
votes
3 answers

How can a template argument after variardic arguments be inferred?

I have the following template function: template void call(const char *name, Args...args, Func f) { f(3); } When I try to use it, like call("test", 1, 2, 3, [=](int i) { std::cout<< i; }); The compiler…
Kurt Pattyn
  • 2,758
  • 2
  • 30
  • 42
3
votes
1 answer

Create a function pointer from Typelist subsets

I have a Typelist implementation very similar to this one. If you don't know what a typelist is: in short, it behaves like variadic templates using nested tuples. You can read more about them here. I would like to build up a function pointer type…
Thibaut
  • 2,400
  • 1
  • 16
  • 28
3
votes
1 answer

C++ parsing function-type template argument

I want to be able to call a function with a template parameter that is of function type (including parameter and return types), i.e. double(int, long), and in the function separate the types and use them individually. For example I want to be able…
Felix Glas
  • 15,065
  • 7
  • 53
  • 82
3
votes
3 answers

variadic template arguments unpacking

For each argument I need apply two nested function: obj.apply(someFilter(arg)); // arg is one argument, but here // should be an unpacking of args I don't know how to write unpacking for such case. I saw this: …
user14416
  • 2,922
  • 5
  • 40
  • 67
3
votes
1 answer

A confusion about variadic templates in c++11 standard

What is the difference between the two functions? template void f(Types... args...){} template void g(Types... args){}
ZhangXiongpang
  • 280
  • 2
  • 7
3
votes
3 answers

C++ polymorphism with variadic function parameter

I am sharing with you an issue that I got with a class using variadic function parameters. It is the class Thread shown in the following code. It is a wrapper of std::thread in order to use the function pattern. I wanted to use polymorphism with…
canercandan
  • 41
  • 1
  • 4
3
votes
3 answers

Are there any real cases proving that 'sizeof...' is necessary?

I wonder about the advantages of the new operator sizeof... (not to be confused with the sizeof operator). I searched the web and found a few examples that seem all like the following one: template std::size_t GetLength() { …
xmllmx
  • 39,765
  • 26
  • 162
  • 323
3
votes
1 answer

Confused with simple mix of non-type templates and functions returning tuple

As exercise, I am trying to write 2 simple functions taking a non-type template int N. The first one needs to create a tuple consisting of N copies of some object of type T. I would like it to resemble the following: template
NickV
  • 1,576
  • 1
  • 10
  • 8
3
votes
1 answer

Bug in variadic function template specialization with MSVC?

Using the Visual Studio Nov 2012 CTP, which supports variadic templates (among other things). The following code: template void myfunc(Args... args) { } template<> void myfunc<1, float>(float) { } produces the following…
Andrei Tita
  • 1,226
  • 10
  • 13
3
votes
2 answers

Explicit specialization using variadic parameters within variadic templated class [MSVS '12: Nov. '12 CTP: error C3522]

I'm trying to expand a class's variadic template type list within a child method as such: template struct Foo { template // error C3522: 'P' : parameter // pack cannot be expanded in this context …
LostOfThought
  • 113
  • 1
  • 6
3
votes
2 answers

Calling std::make_tuple with lambdas in a variadic template - is this supposed to work in C++11?

in C++11 a lambda function is an object, and it should be possible to call make_tuple with it, right? void foobar() { auto t = std::make_tuple([](){ std::make_shared(); }); } This code works for me. Now what happens if we add a variadic…
Gart
  • 2,297
  • 1
  • 28
  • 36
1 2 3
99
100