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.
Questions tagged [variadic]
668 questions
6
votes
1 answer
Is Boost.Tuple compatible with C++0x variadic templates?
I was playing around with variadic templates (gcc 4.5) and hit this problem :
template
boost::tuple
my_make_tuple(Args... args)
{
return boost::tuple(args...);
}
int main (void)
{
boost::tuple…

Arzar
- 13,657
- 3
- 25
- 25
6
votes
2 answers
Multikey map using variadic templates
I'm trying to implement a map with different access keys using variadic templates in c++. What I want to get is to make such syntax work:
MultikeyMap map1; // int and double are keys, float is value type
map1[ 2 ] = 3.5;
map1[…

Grigor Gevorgyan
- 6,753
- 4
- 35
- 64
6
votes
4 answers
A clean way to store a function and its (arbitrary-type, arbitrary-number) arguments
For a library, I'd like a function to accept another function and its arguments, then store them all for calling later. The arguments must allow for any mixture of types, but the functions only need to return void. Something like this:
void…

JKSH
- 2,658
- 15
- 33
5
votes
1 answer
How to override a variadic method in Objective-C
I'm trying to extend a class that has a variadic method such as:
- (void)someMethod:(id)arguments, ... ;
and in the subclass override it by calling the original method like:
- (void)someMethod:(id)arguments, ... {
[super someMethod:arguments,…

Taketo Sano
- 499
- 4
- 14
5
votes
2 answers
C++: Get head and tail of a parameter pack
How to obtain the first n elements of a parameter pack? Or the last n elements, or a slice of elements in [n, n+1, ..., m) in general? For instance:
head<3>(1, 2.0f, "three", '4') => make_tuple(1, 2.0f, "three")
tail<2>(1, 2.0f, "three", '4') =>…

Chih-Long Lin
- 51
- 1
5
votes
2 answers
How to call C++ functions with variable number of arguments from C code
I have to use a third-party C++ library (that I can not change) and call its API from C code.
For most of the library APIs I use a wrapper as explained in this post:
How to call C++ function from C?
But there is one API that takes a variable number…

Julien Brongniart
- 79
- 2
5
votes
1 answer
Tactics with variable arity
Say I want to have a tactic to clear multiple hypothesis at once, to do something like clear_multiple H1, H2, H3.. I tried to do that using pairs, like the following:
Ltac clear_multiple arg :=
match arg with
| (?f, ?s) => clear s; clear_multiple…

Bromind
- 1,065
- 8
- 23
5
votes
1 answer
Python 3 types, custom variadic generic type with arbitrary number of contained types, how?
The class typing.Tuple can be used as with arbitrary number of type arguments, like Tuple[int, str, MyClass] or Tuple[str, float]. How do I implement my own class that can be used like that? I understand how to inherit from typing.Generic. The…

Ray
- 7,833
- 13
- 57
- 91
5
votes
2 answers
Convert initializer_list to variadic templates
I use a formatting library called fmt (http://fmtlib.net/latest/).
One of the possible use is :
fmt::format("Hello, {name}! The answer is {number}. Goodbye, {name}.", fmt::arg("name", "World"), fmt::arg("number", 42));
I'd like to wrap this call in…

Oodini
- 829
- 1
- 6
- 16
5
votes
3 answers
How to iterate over variadic function with std:string arguments?
void foo(std::string arg, ...) {
// do something with every argument
}
Lets say I want to be able to take every string argument and append an exclamation mark before printing it out on a new line.

James
- 2,742
- 1
- 20
- 43
5
votes
1 answer
How can I access the types of a lambda in c++0x?
How is it possible to access the types of the parameters of a lambda function in c++? The following does not work:
template struct capture_lambda {
};
template struct capture_lambda {
static void exec() {
…

axilmar
- 836
- 1
- 13
- 17
5
votes
2 answers
Racket macro that defines multiple top-level forms?
I found myself defining syntax parameters with identical definitions except for their name so I decided to write a macro to make this simpler:
(define-syntax (test-case-parameter stx)
(syntax-parse stx
[(_ parameter:id)
…

Joseph Garvin
- 20,727
- 18
- 94
- 165
5
votes
1 answer
How are the MAX and MIN functions implemented in Fortran without support for variadic functions?
Unless I'm mistaken, there is no way in Fortran to write a function or subroutine with an arbitrary number of arguments (known more succinctly as a variadic function).
For example:
RESULT = FUNC(A1, A2 [, A3 [, ...]])
I know, I can create optional…

EMiller
- 2,792
- 4
- 34
- 55
5
votes
2 answers
Variadic template function where return type depends on template argument list
I am getting a "wrong number of template arguments (2, should be 1)" error that I can't really understand.
I have a class that provides some helper function for other types that want to interact with it, setting a first template parameter on which…

bluewater2
- 160
- 7
5
votes
1 answer
Practical usage of params indexer
Recently, I have found out that indexer can accept an array of arguments as params:
public class SuperDictionary
{
public Dictionary Dict { get; } = new Dictionary();
public IEnumerable…

Yeldar Kurmangaliyev
- 33,467
- 12
- 59
- 101