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
3
votes
2 answers

Create a tuple from a vector of strings in c++

I have a vector of strings, each of which is the result of applying std::to_string to some basic datatype (eg char, int, double). I would like a function to undo this into a tuple of the appropriate types. I have a simple function template to…
3
votes
0 answers

c++ variadic template into AND statement

I am trying use a variadic template in an && statement, but i dont know how to actually do it. Can somebody explain to me how i can programm a function like this one: using EntitySet = std::vector; template EntitySet…
Dolfos
  • 98
  • 1
  • 9
3
votes
3 answers

Cocoa - Calling a variadic method from another variadic one (NSString stringWithFormat call)

I have a problem with [NSString strigWithFormat:format] because it returns an id, and I have a lot of code where I changed a NSString var to an other personal type. But the compiler does not prevent me that there are places where a NSString is going…
Oliver
  • 23,072
  • 33
  • 138
  • 230
3
votes
2 answers

Swift 3: Method expecting variadic String parameter can only receive single String argument

I'm calling a method expecting a String... variadic parameter, but the only thing it allows receiving from the enclosing function is a plain String. My method looks like this: public func deleteKeys(keysReceived:String...,…
Tyress
  • 3,573
  • 2
  • 22
  • 45
3
votes
2 answers

How to make a "variadic" vector like class

I am trying to make class that acts as multidimensional vector. It doesn't have to do anything fancy. I basically want to have a "container" class foo where I can access elements by foo[x][y][z]. Now I would also need similar classes for foo[x][y]…
3
votes
1 answer

How to write a bitmask in c++14 using (something like?) variadic templates

I want to write an efficient way to write 0 and 1 in a byte (or any other type). For instance, in C we can write something like: uint8_t x = 0x00; x|= (1 << 2) | (1 << 4); to write 1 in bits 2 and 4. (of course, you don't use 2 and 4, but use…
Antonio
  • 579
  • 1
  • 3
  • 12
3
votes
3 answers

Push_back variadic function parameters into a vector?

I am trying to push_back the parameters of a variadic function as shown below, but the compiler says there is a type mismatch (due to the parameters being a general type while the vector is int). What should I do to make the parameters…
Ansel Chang
  • 183
  • 1
  • 1
  • 9
3
votes
2 answers

C++ - Check if all template arguments are power of 2

I`am trying to find a simple way of checking if parameters passed as template arguments are all power of 2. I found a bithack on the website and I have this: constexpr bool isPowerOf2(size_t value){ return !(value == 0) && !(value & (value -…
TomW
  • 43
  • 4
3
votes
4 answers

Passing variadic class template's sub-classes to function that only accepts the base class (via parameter pack deduction/inference)

**I've gotten a few suggestions to make my function pure generic, which would work, but I'd prefer limiting the function to only accept Base and its children. Having trouble making a function that can accept arguments of a variadic template class…
Brett Rossier
  • 3,420
  • 3
  • 27
  • 36
3
votes
1 answer

Correct way to use prctl()

The prototype of prctl is int prctl(int option, unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5); in the man page whereas in the header it is declared as a variadic function: extern int prctl (int __option,…
sigsegv
  • 73
  • 3
3
votes
2 answers

Too many template parameters in template redeclaration

. Hi :-) I have the following code : the goal is to return a function that is the sum of other functions, roughly. And to learn about variadic templates. #include template struct FSum { FSum(F f) : f_(f) {} ; int…
Shawn
  • 593
  • 4
  • 12
3
votes
1 answer

Disambiguating argument-less function calls in variadic class hierarchies

I am trying to provide users of a class (MyGizmo below) that derives from a variadic hierarchy (ObjGetter below) with a simple, uncluttered way to unambiguously call a member function that takes no arguments (check() below). I can make this work…
Laurent Itti
  • 165
  • 4
3
votes
5 answers

Strange behavior (SEGFAULT) of a C program using stdargs (va_start)

I wrote a variadic C function which mission is to allocate the needed memory for a buffer, and then sprintf the args given to this function in that buffer. But I'm seeing a strange behavior with it. It works only once. If I have two calls for this…
sandra
  • 450
  • 1
  • 5
  • 18
3
votes
2 answers

List-initializer and variadic constructor

From CPP reference on list-initialisation: Otherwise, the constructors of T are considered, in two phases: All constructors that take std::initializer_list as the only argument, or as the first argument if the remaining arguments have default…
AntiElephant
  • 1,227
  • 10
  • 18
3
votes
2 answers

Cannot explain ambiguous template specializations

Given template struct Pack; using T1 = std::tuple; using T2 = std::tuple; TupleTree shall be Pack< Pack, Pack, Pack, Pack, …
prestokeys
  • 4,817
  • 3
  • 20
  • 43