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

C++ : Function overloading vs Variadic function vs Variadic template vs default parameter

I have seen these questions: Overload a method or use default values? c++ function overloading vs default argument in c++ but they do not consider variadic functions and variadic template . Consider the problem of writing a function to find the…
sonus21
  • 5,178
  • 2
  • 23
  • 48
3
votes
0 answers

variadic templates and GCC printf attribute

Question How to use GCC's printf format attribute with C++11 variadic templates? is similar to mine, but I made more progress on the way to a solution. GCC 4.8.1. Leaving aside the (in)efficiency issue, take the following method template
Andrew Lazarus
  • 18,205
  • 3
  • 35
  • 53
3
votes
1 answer

Implementing a function that perfect-forwards to std::thread

I am trying to write a wrapper around std::thread: #include #include struct A {}; template void lifted_lambda_1(void *m, F &&entrypoint, Args&&... args) { std::cout << "I will do something…
tohava
  • 5,344
  • 1
  • 25
  • 47
3
votes
2 answers

How do I pass on a variadic argument list while keeping a single argument

Suppose I have a base class that might later be "extended" by deriving from it, let's call this class Base, and the extension Derived. The template signature of the classes is fixed, and cannot be altered (ie. we cannot change the template arguments…
quant
  • 21,507
  • 32
  • 115
  • 211
3
votes
3 answers

Non-type template parameters in function and in inheritance

I'm following this great tutorial. The author heavily uses variadic templates and I came to a point where I'm stuck, can't understand. Can you help me? 1. Why isn't this compiling? // this is simple template struct…
nikitablack
  • 4,359
  • 2
  • 35
  • 68
3
votes
1 answer

C++11 Translating a variadic template to deduce a class type

i would like to generate classes from a list of class properties. For each property, the implementation is deduced through a template. For the sake of the question i will illustrate my problem by trying to create a class to handle a virtual entity…
Deidril
  • 33
  • 6
3
votes
2 answers

Tuple and variadic templates, how does this work?

I have seen people write (on stack overflow itself, asking some even advanced concepts) something along the lines of: template std::tuple parse(istream stream) { return std::make_tuple(args(stream)...); } and use it…
Arun
  • 3,138
  • 4
  • 30
  • 41
3
votes
0 answers

C++: manually create a variadic template parameter pack

I'd like to be able to do something like this: Given a function: void some_func(int a, int b, int c) { cout << a << b << c; } void generic_call(vector& v) { Args... args((v)); …
shoosh
  • 76,898
  • 55
  • 205
  • 325
3
votes
3 answers

Default initialized (with value initialization) parameter pack

Can I default initialize a parameter pack to the respective value initialization of each type ? To elaborate a bit more, take the example of a simple function template template void f(T arg = T()) { // eg for T=int, arg is 0 (value…
Lorah Attkins
  • 5,331
  • 3
  • 29
  • 63
3
votes
2 answers

Deduce types pack from a variadic-templated class and declare an argument of the same types pack

First off, sorry for unclear question title, feel free to edit if you think of a better way to state it. I have a class: template class CSignal { template void invoke(ActualArguments&&...…
Violet Giraffe
  • 32,368
  • 48
  • 194
  • 335
3
votes
1 answer

std::forward or std::forward?

I have come across two variants of std::forward usage with variadic template arguments. template void foo(Args&&... arga) { bar(std::forward(args)...); // variant 1 bar(std::forward(args)...); //…
n. m. could be an AI
  • 112,515
  • 14
  • 128
  • 243
3
votes
2 answers

Calling a zero argument template function pointer with variadic template argument?

Here is a code snippet from a post at Functional C++ blog, describing how a generalized function evaluation can be implemented. My question is how can you declare template function pointer f like R(C::*f)() with no arguments and still be able to…
Benji Mizrahi
  • 2,154
  • 2
  • 23
  • 38
3
votes
1 answer

Executing function for each packed parameter in variadic template

I noticed the following line in the open-source project FeatherKit: int _[] = { (SubscribeToType( bus, receiver, desubscribers, unsubscribe ), 0)... }; With the following context: template void Subscribe(…
Frank
  • 97
  • 2
  • 8
3
votes
1 answer

Variadic template-based multiple inheritance for two interacting classes...

In my current project, I need to be able to provide template-based multiple inheritance (Mixin pattern) and have two classes (with mirroring multiple-inheritance trees) that can interact together (i.e. one uses methods from the other one at the same…
Dave
  • 291
  • 2
  • 13
3
votes
2 answers

Why does a pack expansion inside an unevaluated operand result in the last element?

I can do this inside decltype(): auto g() -> decltype(1, "", true, new int); But not this: template auto g(Args&&... args) -> decltype(args...); It fails because a pack expansion appears inside decltype() but I thought a pack…
template boy
  • 10,230
  • 8
  • 61
  • 97