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
20
votes
3 answers
Objective-C passing around ... nil terminated argument lists
Having some issues with the ... in ObjectiveC.
I'm basically wrapping a method and want to accept a nil terminated list and directly pass that same list to the method I am wrapping.
Here's what I have but it causes an EXC_BAD_ACCESS crash. …

Alex Wayne
- 178,991
- 47
- 309
- 337
18
votes
4 answers
Why is `boost::any` better than `void*`?
What inherent advantages do boost::any and boost::any_cast offer over using void* and dynamic_cast?

Paul Manta
- 30,618
- 31
- 128
- 208
18
votes
2 answers
C++/C++11 - Switch statement for variadic templates?
Let's say I have a few structs like this:
struct MyStruct1 {
inline void DoSomething() {
cout << "I'm number one!" << endl;
}
};
struct MyStruct2 {
static int DoSomething() {
cout << "I'm the runner up." << endl;
…

nonoitall
- 1,232
- 1
- 15
- 25
18
votes
4 answers
Is safe to use va_start macro with this as parameter?
I have to use IAR compiller in embedded application (it does not have namespaces, exceptions, multiple/virtual inheritance, templates are bit limited and only C++03 is supported).
I can't use parameter pack so I tried to create member function with…

user11373693
- 183
- 7
15
votes
1 answer
pre-typedef'ing a variadic-function-pointer argument
I have a function foo that takes a variadic function pointer as its argument.
I would like to use "using" to define the argument's type prior to the function declaration.
template
using TFuncType = void(*)(vARGS ...…

xaxazak
- 748
- 4
- 16
14
votes
1 answer
Variadic compose function?
I'm trying to write a variadic function composition function. Which is basically the (.) except that the second argument function is variadic. This should allow expressions like:
map even . zipWith (+)
or just
map even . zipWith
Currently what…

is7s
- 3,500
- 1
- 20
- 41
14
votes
3 answers
Repeated use of a variadic function argument doesn't work
I have a function that tries to log stuff to the console and also to a log file, but it doesn't work. The second use of the variable length argument gives garbage written to the console. Any ideas?
void logPrintf(const char *fmt, ...) {
…

Neddie
- 141
- 1
- 6
14
votes
4 answers
How do vararg functions find out the number of arguments in machine code?
How can variadic functions like printf find out the number of arguments they got?
The amount of arguments obviously isn't passed as a (hidden) parameter (see a call to printf in asm example here).
What's the trick?

masterxilo
- 2,503
- 1
- 30
- 35
14
votes
3 answers
How to properly use references with variadic templates
I have something like the following code:
template
void inc(T1& t1, T2& t2, T3& t3, T4& t4) { ++t1; ++t2; ++t3; ++t4; }
template
void inc(T1& t1,…

Hippicoder
- 1,565
- 3
- 17
- 21
14
votes
4 answers
Check if parameter pack contains a type
I was wondering if C++0x provides any built-in capabilities to check if a parameter pack of a variadic template contains a specific type. Today, boost:::mpl::contains can be used to accomplish this if you are using boost::mpl::vector as a substitute…

Sumant
- 4,286
- 1
- 23
- 31
13
votes
3 answers
Iterate over C++ variadic template
I have the following:
template
Sender *createSenderChain() {
return new FIRST(new SECOND());
}
Is it possible to make the template variadic:
template
Sender *createSenderChain()…

user2479653
- 509
- 5
- 14
13
votes
2 answers
A variadic template method to accept a given number of doubles?
template class myclass
{
public:
template void mymethod(Args... args)
{
// Do interesting stuff
}
};
I want mymethod to be called only with exactly N doubles. Is that possible? That is, say…

Matteo Monti
- 8,362
- 19
- 68
- 114
13
votes
4 answers
Macro to count number of arguments
I have a variadic function from a third-party C library:
int func(int argc, ...);
argc indicates the number of passed optional arguments.
I'm wrapping it with a macro that counts the number of arguments, as suggested here. For reading convenience,…

Eitan T
- 32,660
- 14
- 72
- 109
12
votes
3 answers
Is there a way to use C++ preprocessor stringification on variadic macro arguments?
My guess is the answer to this question is no, but it would be awesome if there was a way. To clarify, assume I have the following macro:
#define MY_VARIADIC_MACRO(X...) // Does some stuff here in the macro definition
What I would like to do is…

Hazok
- 5,373
- 4
- 38
- 48
12
votes
3 answers
C++ call function with many different types
I have an overloaded function that I have to call with many different types. The simple approach is:
uint8_t a;
uint16_t b;
//....
double x;
doSomething(a);
doSomething(b);
//...
doSomething(x);
expressing those calls succinctly can be done with a…

marco
- 243
- 1
- 9