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

std::tuple<> of one std::shared_ptr<> does not work?

I recently discovered a problem with using std::tuple<> for just one element. I created a class for type erasure and retaining N number of reference counted objects. However the reference counted object is not retained if it is the only one in the…
Aaron Albers
  • 157
  • 6
4
votes
3 answers

C variadic wrapper

To output formatted debug output, I've written a wrapper for vsfprint. Now, I wanted to allocate exactly enough memory for the output buffer, instead of just claiming a random high buffer size (it's a small embedded platform (ESP8266)). For that I…
svenema
  • 1,766
  • 2
  • 23
  • 45
4
votes
3 answers

How to check the type of passed arguments to variadic function

I'm new to variadic templates and for the sake of learning consider the following function template T* make_arr(args... arg) { // Code to check if passed args are of the same type T* arr = new…
Laith
  • 1,248
  • 2
  • 11
  • 19
4
votes
1 answer

C++ - deduce parameter pack (variadic template) constructor and copy constructor by enable_if_t

Update: Thank you, Jamboree. This is the final struct A. struct A { template> A(Args &&...args) { cout<<'v'; } template
Caesar
  • 971
  • 6
  • 13
4
votes
3 answers

C++ Vector Template Per-Component Operations

I'm rewriting the vector math portion of my project, and I'd like to generalize vectors by their type and number of dimensions. A vector represents an N dimensional vector of type T. template struct vector { T…
Janz
  • 41
  • 1
4
votes
2 answers

Obtaining a pack of packs

This is a very tough one (for me at least). I'll start off by discussing an easier task that I've already solved. ExpandPacks::type is a pack of all packs obtained from taking one type from each pack in Packs.... For…
prestokeys
  • 4,817
  • 3
  • 20
  • 43
4
votes
2 answers

Functional composition with variadic templates

My goal is to get composition of functions working with this exact syntax: int main() { Function f([](const std::string& s) {return s.length();}); Function g([](int x) {return x + 0.5;}); Function
prestokeys
  • 4,817
  • 3
  • 20
  • 43
4
votes
1 answer

Does c++0x tuple use the new variadic templates or Boost's macro-fied tuple implementation?

I read it was based on Boost's version, but I wasn't quite sure what that meant when it came down to implementation. I know Boost does their own variadic template, but I would assume c++0x would use its own variadic templates for the new tuple.
Brett Rossier
  • 3,420
  • 3
  • 27
  • 36
4
votes
1 answer

What is the use of variadic constructor in C++?

Consider following program: #include struct Test { Test(...) { std::cout<<"Variadic constructor\n"; } }; int main() { Test t; t={3,4,5}; } I think it is variadic constructor. Does the C++ standard says that…
Destructor
  • 14,123
  • 11
  • 61
  • 126
4
votes
2 answers

How to expand macro and delete comma

For example I want to write my own printf() alternative, but I have to perform calculations on the variable arguments: #define log(fmt_string, ...) my_log(fmt_string, pack_args(__VA_ARGS__), __VA_ARGS__) where pack_args(...) - is a macro too. How…
Anton Kochkov
  • 1,117
  • 1
  • 9
  • 25
4
votes
1 answer

How to use variadic templates to wrap a variable number of function arguments?

I want to take a variable number of function arguments, and in the function itself, wrap each function argument using a template wrapper class and pass these wrapper classes as arguments to another function. Say if I have a template class that…
Tony
  • 153
  • 6
4
votes
3 answers

Deduce template parameter pack from function call

I have the following code, where I have a template class, and a type in it, which I would like to use in a separate template function. template struct MyClass { enum SomeEnum { value0 = -1 }; }; template
simon
  • 1,210
  • 12
  • 26
4
votes
1 answer

Pairing compatible types obtained randomly from variadic templates

A Bow can only fire a Missile of type Arrow, Bolt, or Dart (but not a Stone), and can only go with a MissileContainer of type Quiver or Case. A Quiver can only hold Arrows or Bolts, and a Case can only hold Bolts, Darts, or Stones. I've declared…
prestokeys
  • 4,817
  • 3
  • 20
  • 43
4
votes
1 answer

Recursive inheritance with variadic templates

Consider the following code: #include struct ActionOption { virtual void foo(int) const = 0; }; template struct ActionType; template <> struct ActionType<0> : ActionOption { virtual void foo(int) const override {std::cout…
prestokeys
  • 4,817
  • 3
  • 20
  • 43
4
votes
1 answer

stringstream with recursive variadic function?

I want to be able to combine multiple different arguments into a single string using ostringstream. That way I can log the resulting single string without any random issues. I got this far: template void MagicLog(T t) { …
ManIkWeet
  • 1,298
  • 1
  • 15
  • 36