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
1 answer

C++0x passing arguments to variadic template functions

What does it mean to take a variable number of arguments by reference? Does it mean that each of the arguments are passed by reference? Consider for example the following functions which performs some processing on each its arguments: void f() //…
HighCommander4
  • 50,428
  • 24
  • 122
  • 194
3
votes
1 answer

Is this syntax legal?

When I uncomment the line in main() below, Visual Studio 2015 won't compile (the code compiles otherwise). #include #include template struct RemoveLastHelper; template
prestokeys
  • 4,817
  • 3
  • 20
  • 43
3
votes
1 answer

Binary search using variadic templates and lambda functions

Consider this, struct Person { std::string name; Person (const std::string& n) : name(n) {} std::string getName(int, char) const {return name;} // int, char play no role in this // simple example, but let's suppose that they are…
prestokeys
  • 4,817
  • 3
  • 20
  • 43
3
votes
1 answer

Passing variadic template argument pack to next function

I have done my own reimplementation of printf() (classic) in my debugging code. template void Printf(wchar_t const * message, T value, Args ...args); void Printf(wchar_t const * message); void…
Antiusninja
  • 157
  • 1
  • 17
3
votes
2 answers

Arbitrary dimensional array using Variadic templates

How can I create an Array class in C++11 which can be used like Array < int, 2, 3, 4> a, b; Array < char, 3, 4> d; Array < short, 2> e; and access it in a way like a[2][1][2] = 15; d[1][2] ='a'; I also need to overload operator as T…
3
votes
2 answers

Inserting any number of types into a pack of template arguments

InsertTypes, Is...>::type is Pack with the types Ts... inserted in positions Is..., respectively. For example, InsertTypes, Pack, 2,4,1>::type, is Pack
prestokeys
  • 4,817
  • 3
  • 20
  • 43
3
votes
2 answers

Limiting the number of arguments in a variadic function

So I've been working on a function class, and by default, I can do this, and it works: int main(){ function f("x^2+1"); cout<
blackbeltJR
  • 51
  • 1
  • 5
3
votes
2 answers

Generic allocator class without variadic templates?

I am trying to write a generic allocator class that does not really release an object's memory when it is free()'d but holds it in a queue and returns a previously allocated object if a new one is requested. Now, what I can't wrap my head around is…
rainer
  • 31
  • 2
3
votes
4 answers

About variadic templates

I'm currently experiencing with the new c++0x variadic templates, and it's quite fun, Although I have a question about the process of member instantiation. in this example, I'm trying to emulate the strongly typed enum with the possibility of choose…
chedi
  • 298
  • 3
  • 12
3
votes
1 answer

Initialization of variadic base classes

The following code doesn't work. Its intent is to pass arguments to variadic base classes. Is this possible, and if so, what's the right way to implement it? (Clang's error message is: an initializer for a delegating constructor must appear alone,…
foxcub
  • 2,517
  • 2
  • 27
  • 27
3
votes
1 answer

dependent types with variadic templates

Can you see anything wrong with this function declaration? template std::tuple foo(const Containers &...args); When I try to call it, like this: foo(std::list(),…
slyqualin
  • 297
  • 2
  • 12
3
votes
1 answer

How do I define a macro with variadic method in objective-C?

The method I am trying to call is; - (void)addLogWithLevel:(MDCLogLevel)logLevel logContent:(NSString *)logContent, ... { va_list args; va_start(args, logContent); NSString *message = [[NSString alloc] initWithFormat:logContent …
MattCheetham
  • 430
  • 1
  • 5
  • 10
3
votes
2 answers

Combine two variadic function results

Suppose I have two variadic functions like this: function a(num) if num == 1 then return 1 else return 1, 2 end end function b(num) if num == 1 then return 1 else return 1, 2 end end I then want to build another…
Stratus3D
  • 4,648
  • 4
  • 35
  • 67
3
votes
5 answers

how to help programmer write safe and correct printf calls in C?

[Updated organization and content for clarity] The Real Question What would be a good way, for C, to help a programmer, while s/he's typing, write safe and correct calls to project-specific printf-like debugging functions? C macros? C wrapper…
talkaboutquality
  • 1,312
  • 2
  • 16
  • 34
3
votes
2 answers

C++ : create custom function dispatcher from variadic template

I have some functions that read various types from serialized data, eg: class DataDeserializer { int getInt(); std::string getString(); MyClass getMyClass(); } I then have various callback functions that take arbitrary parameters,…
gimmeamilk
  • 2,016
  • 5
  • 24
  • 36