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
7
votes
2 answers
cpp: catch exception with ellipsis and see the information
I know that you can catch "all exceptions" and print the exception by
try
{
//some code...
}catch(const std::exception& e) {
cout << e.what();
}
but this is just for exceptions derived from std::exception.
I was wondering if there is a way…

ZivS
- 2,094
- 2
- 27
- 48
7
votes
4 answers
C++ overloading operator comma for variadic arguments
is it possible to construct variadic arguments for function by overloading operator comma of the argument? i want to see an example how to do so.., maybe something like this:
template class ArgList {
public:
ArgList(const T& a);
…

uray
- 11,254
- 13
- 54
- 74
7
votes
4 answers
Passing parameters dynamically to variadic functions
I was wondering if there was any way to pass parameters dynamically to variadic functions. i.e. If I have a function
int some_function (int a, int b, ...){/*blah*/}
and I am accepting a bunch of values from the user, I want some way of passing…

tommobh
- 71
- 1
- 2
6
votes
1 answer
Unpacking Variadic Parameter Pack of Enums
Update: Edited to fix compilation in working example.
I want to do something like the following so the function can take in both a list of the enum class instances or a struct that holds them, but the definition of auto myFunc2>…

AlethicSupporter
- 75
- 5
6
votes
1 answer
What is a good typesafe alternative to variadic functions in C++?
In joint with this question. I am having trouble coming up with a good type safe solution to the following seemingly basic problem. I have a class music_playlist that has a list of the songs it should play. Seems pretty simple right, just make an…

Skyler Saleh
- 3,961
- 1
- 22
- 35
6
votes
2 answers
how can a c++ concept combine concepts?
I have inherited the following:
template
concept IsAwaiter = requires {
typename T::await_ready;
typename T::await_suspend;
typename T::await_resume;
};
template
concept IsAwaitables = typename…

Bob Pretzker
- 95
- 6
6
votes
1 answer
C: passing arguments from variadic function to variadic macro
I have a standard logging API built into my C code, a nice simple logF(const char *pFormat, ...) thing which has always, so far, been mapped to vprintf(), i.e.:
void logF(const char *pFormat, ...)
{
va_list args;
va_start(args, pFormat);
…

Rob
- 865
- 1
- 8
- 21
6
votes
1 answer
Is it possible to automatically implement a trait for any tuple that is made up of types that all implement the trait?
Suppose that I have a
trait Happy {}
I can implement Happy for whatever struct I might want, for example:
struct Dog;
struct Cat;
struct Alligator;
impl Happy for Dog {}
impl Happy for Cat {}
impl Happy for Alligator {}
Now, I would like to…

Matteo Monti
- 8,362
- 19
- 68
- 114
6
votes
5 answers
What's the equivalent in Perl 6 to star expressions in Python?
In Python 3, suppose you run a course and decide at the end of the semester that you’re going to drop the first and last homework grades, and only average the rest of them:
def drop_first_last(grades):
first, *middle, last = grades
return…

chenyf
- 5,048
- 1
- 12
- 35
6
votes
2 answers
how to write variadic function for any number of string concatenation in c++
I am a newbie in c++. I know this is a very common question, but I want a complete code to concat any number of strings which are passed to function in c++. I am calling the function as:
string…

M. Paul
- 361
- 5
- 18
6
votes
1 answer
Ltac : optional arguments tactic
I want to make a Ltac tactic in coq which would take either 1 or 3 arguments. I have read about ltac_No_arg in the LibTactics module but if I understood it correctly I would have to invoke my tactic with :
Coq < mytactic arg_1 ltac_no_arg…

L. Soret
- 169
- 10
6
votes
4 answers
template Metaprogramming: multiplying a bunch of template arguments
I need to compute the product of a bunch of numbers at compile time passed to a templated struct. I succeeded to make an ugly solution :
template
struct mul_all
{
static constexpr std::size_t value = n1 *…

chedy najjar
- 631
- 7
- 19
6
votes
3 answers
What does this compiler warning generated by `-pedantic` mean?
What does this GCC warning mean?
cpfs.c:232:33: warning: ISO C99 requires rest arguments to be used
The relevant lines are:
__attribute__((format(printf, 2, 3)))
static void cpfs_log(log_t level, char const *fmt, ...);
#define log_debug(fmt, ...)…

Matt Joiner
- 112,946
- 110
- 377
- 526
6
votes
1 answer
Parameter pack with default template argument
In this code, I'm trying to generalize Test from using Arg to using Args.... The problem is the default template argument. What I have below compiles, except when I uncomment the commented-out line in main():
#include
#include…

prestokeys
- 4,817
- 3
- 20
- 43
6
votes
3 answers
Function pointer with variadic template arguments
Referring to the code below, can someone figure out how to adapt
template
RET Mediator::change (Object* o, RET (Object::*f)(ARGS1...), ARGS2&&... args) {
const std::tuple…

prestokeys
- 4,817
- 3
- 20
- 43