Questions tagged [parameter-pack]

171 questions
4
votes
2 answers

Combining function parameter pack and default arguments

I have a function with a parameter pack: template void tprintf(const char* format, Targs... args) {} (the implementation shouldn't matter, just the signature). I want to add source position as default argument, using the…
Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487
4
votes
1 answer

Must I explicitly show the types in the parameter pack when instantiate a template?

I got a example to illustrate my question: #include class Foo { public: Foo(int i) {} }; template class Bar { public: T t; Bar(Args &&... args) : t(std::forward(args)...) {} }; and if I want…
user2269707
3
votes
1 answer

Can we use int... as an argument for template parameter pack directly?

Here is my problem: template struct iniClass { private: std::initializer_list m_data; int x; public: iniClass(Ts... vars) : m_data({vars...}), x(8) { std::cout << "created object with first…
Rango
  • 217
  • 8
3
votes
3 answers

Remapping a tuple onto another tuple

I am attempting to convert between two types of std::tuples but I'm having trouble getting the implementation right. I want it to map if the type is the same, but it needs to allow duplicate types to get mapped in the original order. The basic…
bpmckinnon
  • 125
  • 4
3
votes
2 answers

How to specify a default argument for a template parameter pack?

I have the following method template void doSomething() { ... }; It seems not possible to supply default values for Indices, e.g. template
3
votes
1 answer

unpack a parameter pack of pairs into an array and a tuple

So i have a list of pairs where the first member is a constant integer and the second is a type, is there anyway to unpack it into an array of the first member and a tuple of the second members? struct MA {} struct MB {} struct MC {} template
fluter
  • 13,238
  • 8
  • 62
  • 100
3
votes
2 answers

Compile-time set subtraction of two tuples

I have an application where I am constructing tuple out of a parameter pack: template struct foo { typedef std::tuple A; } And I have another tuple-type B defined as: typedef std::tuple B; Is there a way to obtain a…
Blizzard
  • 1,117
  • 2
  • 11
  • 28
3
votes
2 answers

Get member from last possible class of a parameter pack

I want to get the value of a member variable of the last possible class in a parameter pack. For eg. I want getLastB(a_, b_, c_, d_) to return 100 in the code below (the value of c_.b), and not 40 (the value of b_.b) #include #include…
3
votes
1 answer

Incrementing every value in a parameter pack

I am currently attempting to increment every value in a parameter pack full of std::vector::iterators of some unknown type. I am currently struggling to get my head around how the ... syntax works. I would have thought to increment every value it…
3
votes
2 answers

Template specialization with Parameter Packs

I'm quite new to c++ but wanted to try to do some fancy template stuff. I am not sure if it is possible, but I am fairly confident there is a way to achieve that. So here's the Issue: I am calling various Hardware function, which requires a number…
Abudinka
  • 85
  • 6
3
votes
0 answers

Does std::thread use parameter packs and if yes then how? :)

I want to achieve a similar result: void somefunc(int var1, char var2){ dosomething(); } int main(){ std::thread t1(somefunc, 'a', 3); return EXIT_SUCCESS; } std::thread takes a function pointer and any number of argments. In my class that…
3
votes
1 answer

Divorce a parameter pack in a class template

I am trying to write a class template that uses a parameter-pack and implements a member function for each type contained in the parameter-pack. This is what I have so far: template class Myclass { public: void…
3
votes
2 answers

How to construct different object according to their types in a template function?

Here is my question, I have a base class Base, two derived classes ClassA and ClassB form Base taking only two arguments, and two classes ClassB0 and ClassB1 derived from ClassB taking three arguments. I want to create class intance accroding to the…
2
votes
1 answer

Inheritance from variadic and construction with parameter pack : default constructor

I have that code : template class Variable : virtual public GenericVar, public Extentions... { static_assert((std::is_base_of_v, Extentions> && ...), "Only virtual base of…
Slane
  • 21
  • 2
2
votes
2 answers

method with template parameter pack is called recursivly indefenetly, and doesnt call overloaded method

I have a logging class, which logs messages of any type: /// log level enum enum level_t { DEBUG, // used for debugging output CPLEX, // used for cplex output INFO, // used for generell informative output WARNING, // used for…
Moritz
  • 378
  • 5
  • 14
1
2
3
11 12