Questions tagged [variadic]

In computer science, an operator or function is variadic if it can take a varying number of arguments; that is, if its arity is not fixed.

668 questions
5
votes
2 answers

Solving the mixin constructor problem in C++ using variadic templates

I've recently tackled the constructor problem, where various mixins classes that decorate each other (and a topmost host class) have different constructor signatures. To maintain a single constructor in the resulting decorated class, and without…
Eitan
  • 862
  • 1
  • 7
  • 17
5
votes
3 answers

Create hash queue with variadic template

I want to build a hash code queue using variadic template. The minimal example code is template void hash_queue(queue& q){ q.push( typeid(T).hash_code() ); } template void hash_queue(queue&…
ztik
  • 3,482
  • 16
  • 34
5
votes
3 answers

Variadic helper function with partial argument pack

In the following code: #include struct Base { virtual ~Base() = default; template void helper (void (T::*)(Args..., int), Args...); void bar (int n) {std::cout << "bar " << n <<…
prestokeys
  • 4,817
  • 3
  • 20
  • 43
5
votes
1 answer

How to code a variadic defmulti/defmethod in clojure

I have a defmulti/defmethod group that take pairs of arguments like so... (defmulti foo "some explanation" (fn [arg1 arg2] (mapv class [arg1 arg2]))) (defmethod foo [N P] (->L 1 2 3)) (defmethod foo [L P] (->N 5)) (defmethod foo [P N] (->L 6 7 8)) …
phreed
  • 1,759
  • 1
  • 15
  • 30
5
votes
2 answers

Perfect-forwaring of the variadic template parameters of a struct

In my C++11 code, I have a variadic struct and a function that should use perfect-forwarding for the struct's variadic types such as this: template struct S { void X(T&&... args) { Do(std::forward(args)...); …
Axel Habermaier
  • 263
  • 3
  • 9
5
votes
1 answer

Forward variadic function arguments to variadic function using C++11

I want to forward calls to a library which has a variadic method. The simplest example I could come up with to replicate the problem is this: void Bar(int useless, ...) { //Does something } template void Foo(int useless, Args...…
ChrisWard1000
  • 526
  • 5
  • 15
5
votes
3 answers

Can a variadic template match a non-variadic template parameter?

Consider the following snippet: template class T,class U> struct apply { typedef T type; }; typedef apply::type tuple_of_one_int; //Should be std::tuple GCC 4.8.2. says: type/value mismatch at argument…
sbabbi
  • 11,070
  • 2
  • 29
  • 57
5
votes
2 answers

Is it possible to generate a parameter pack?

Consider the following pseudo code : template struct worker : unique::type...{}; struct x{}; struct y{}; struct z{}; Is it possible to write a template unique such that it generates a parameter pack consisting of only unique types…
user1436623
  • 73
  • 1
  • 4
5
votes
1 answer

Concatenation of tokens in variadic macros

In C, is it possible to concatenate each of the variable arguments in a a variadic macro? Example: MY_MACRO(A, B, C) // will yield HDR_A, HDR_B, HDR_C MY_MACRO(X, Y) // will yield HDR_X, HDR_Y The normal ## operator has special meaning for…
jbourne
  • 51
  • 1
  • 3
5
votes
2 answers

Can variadic expansions be used as a chain of comma-operator calls?

I was looking at "How to properly use references with variadic templates," and wondered how far comma expansion can go. Here's a variant of the answer: inline void inc() { } template inline void inc(T& t, Args& ...args)…
CTMacUser
  • 1,996
  • 1
  • 16
  • 27
4
votes
2 answers

C++ Paramater pack expansion over chained function calls

It is common for libraries to have types which return instances of themselves from member functions to encourage chaining calls. For example, nlohmann json: auto my_data = my_json_object["first key"]["second key"]; Is there some way to call a…
xzaton jw
  • 41
  • 3
4
votes
2 answers

C++ Instantiate Template Variadic Class

I have this code: #include template void processAll() { P p = P(); p.process(); } class P1 { public: void process() { std::cout << "process1" << std::endl; } }; int main() { processAll(); return…
Dbi
  • 113
  • 1
  • 6
4
votes
3 answers

Smart variadic expansion based on format string

I have a daemon that reads a configuration file in order to know where to write something. In the configuration file, a line like this exists: output = /tmp/foo/%d/%s/output Or, it may look like this: output = /tmp/foo/%s/output/%d ... or simply…
Tim Post
  • 33,371
  • 15
  • 110
  • 174
4
votes
3 answers

variadic template method to create object

I have a variadic template method inside a template class (of type T_) looking like this template < typename T_ > class MyContainer { public: ... template ulong add (A &&...args) { T_ t{args...}; // other stuff…
Elle
  • 305
  • 2
  • 10
4
votes
2 answers

C/C++ build a generic stack frame to call different callback functions

I'm refactoring a C++ application that refers to a bunch a multiple callback functions, each having a different number of arguments and I would like to know if there's a generic way to build a dedicated argument stack frame before calling each of…
Obsidian
  • 3,719
  • 8
  • 17
  • 30