Questions tagged [pack-expansion]

13 questions
26
votes
1 answer

Problem with order of evaluation in parameter pack expansion

I wrote a template that takes an istream& and a function and is supposed to extract all parameters for this function from the istream, call the function with these parameters and return the result. It all works fine, except for the order of…
Lukas-T
  • 11,133
  • 3
  • 20
  • 30
8
votes
1 answer

How to create a template with variable number of type parameters?

In our codebase we use std::variant, ...> a lot. That obviously requires a lot of writing. How to make a template? template using VarSP = std::variant>; Where should T go in the above…
Nurbol Alpysbayev
  • 19,522
  • 3
  • 54
  • 89
7
votes
1 answer

Black Magic using Initializer_list and pack expansion

To expand flexible function parameters, there is a method using std::initializer_list. However I couldn't understand it. Can anyone explain this in an understandable way? template auto print(T value, Args... args) { …
5
votes
1 answer

MSVC vs Clang/GCC bug during overload resolution of function templates one of which contains a parameter pack

I was using parameter pack when I noticed that one such case(shown below) compiles fine in gcc and clang but not in msvc: template void func(T a, T b= T{}) { } template void func(T a, S... b) { } int main() { …
Jason
  • 36,170
  • 5
  • 26
  • 60
3
votes
1 answer

How can you have multiple lines or statements inside a C++ pack expansion?

Suppose that I have some simple code like the one below, which just prints all of the values in a tuple and keeps track of the current iteration. #include #include #include using std::cout; int main() { …
Doot
  • 555
  • 5
  • 15
2
votes
1 answer

How to generalize variadic function fn to fn

Assume there is variadic function template foo(const S& s, Args... args). struct S {}; template void foo(const S& s, Args... args); void check_foo() { S s0{}; S s1{}; char a0 = 0; short a1 = 1; int …
ilynxy
  • 151
  • 4
1
vote
0 answers

How the pattern on a function template argument pack works?

Hello I have this example about variadic function templates and patterns: int& neg(int& x){ x = -x; return x;} void f(int& x){ std::cout << x << ", "; } template void f(T& x, Args&...args){ f(…
Itachi Uchiwa
  • 3,044
  • 12
  • 26
0
votes
1 answer

GCC & Clang vs MSVC Bug while expanding template parameter pack in the same parameter clause for function templates

I came across the following statement in the standard: If a template-parameter is a type-parameter with an ellipsis prior to its optional identifier or is a parameter-declaration that declares a pack ([dcl.fct]), then the template-parameter is a…
Jason
  • 36,170
  • 5
  • 26
  • 60
0
votes
1 answer

Multiple inheritance from a pack expansion

I recently saw this in production code and couldn't quite figure out what it does: template struct pool : pool_type... { //... }; I've never seen pack expansion happening for parent classes. Does it just inherit every type passed…
glades
  • 3,778
  • 1
  • 12
  • 34
0
votes
2 answers

Variadic expansion to access multi-dimensional std::array

Suppose the following multi_array structure: template struct multi_array { using storage_type = typename storage_type::type; using value_type = type; using size_type =…
0
votes
3 answers

Trying to require multiple variadic types to be specific types

This is currently in pseudo code as it is an idea that I'm working on before I begin to write it as full code. I know that I can create a normal variadic function that uses va_arg and va_list such as printf() does, however, I want to avoid using…
Francis Cugler
  • 7,788
  • 2
  • 28
  • 59
0
votes
1 answer

Pass param packed args into a std::queue to call with a different function later

I asked a similar question earlier without realizing that that wasn't quite specific enough. So I have this function that has to take in all the arguments of a print function, with the ... and all, and then put it into a queue that will call the…
0
votes
0 answers

Pass a parameter packed arg list to a queue

What i need to do is have a function that takes in a list of arbitrary arguments, using the parameter pack operator, and put that whole list into a queue from which I can later pass those args into another function. This kind of thing: void…