Questions tagged [parameter-pack]

171 questions
2
votes
1 answer

Q: Template specialization with parameter pack

I'll get right to the question. We have template specialization: class TestClass { public: template static T fn(const T& a); } // OK template T TestClass::fn(const T& a) { // ... magic for any type here ... } //…
2
votes
1 answer

About template class grammar

I want to ask something about the template class. I know the basics like: template class tmp{ ... } However, in the starter file of my programming assignment, I saw a new format as: template class…
2
votes
1 answer

Multiple parameter packs as factory function arguments

I am trying to create a factory method that instantiates a template class by passing the constructor arguments for the component classes as template parameter packs. The ProducerConsumer template is parameterized on the types of the Producer and…
Jeff Benshetler
  • 640
  • 6
  • 13
2
votes
5 answers

C++ template that knows its argument's position

I am new in c++ metaprogramming and few days ago I decided to write a template with variadic parameter pack, that knows in which position in parameter pack stands first int. More precisely I want to have a struct with name GetIntPos and with static…
2
votes
0 answers

How to specify parameter packs that accept any type or value?

When specifying the parameter packs for a type, I want to be able to accept not only typenames but also values of arbitrary types. Example: template // ^^^^^ <- pseudo code struct Example…
bitmask
  • 32,434
  • 14
  • 99
  • 159
2
votes
2 answers

Extract types from std::tuple for a method signature

I am looking for a way to extract the types of an std::tuple to define a method signature. Take the following (contrived) example: template class A { public: typedef RetT ReturnType; typedef…
2
votes
1 answer

Template Meta Programming: How to combine parameter packs to new parameter pack

I'm trying to implement a way of removing some types from a tuple; for instance I want to be able to e.g. only take a tuple of the first 2 template arguments for a tuple depending on a condition: Is it possible to 'pack' the types of which a tuple…
mutableVoid
  • 1,284
  • 2
  • 11
  • 29
2
votes
0 answers

Reverse cumulative product of parameter pack

In c++17 we can easily get the cumulative product of a parameter pack like this: template constexpr std::array cumulative_product(int x0, Xs... xs) { return {x0, x0 *= xs ...}; } constexpr auto cp =…
florestan
  • 4,405
  • 2
  • 14
  • 28
2
votes
1 answer

Parameter pack inside noexcept specifier

Currently in C++ neither of these are possible, the compiler complains that it expects an expression. This appears trivial to me, if you're building a tuple like object with a variadic amount of types, how to check if all those types are nothrow…
João Pires
  • 927
  • 1
  • 5
  • 16
2
votes
1 answer

Does parameter packs carry a set limit?

Is there any upper limit to, or maximum number of elements of Parameter packs like there is for maximum template recursion depth ?
darune
  • 10,480
  • 2
  • 24
  • 62
1
vote
1 answer

Use parameter pack in template parameters list

I want to write an abstract Pipeline class that gets some functions with a specific signature as template parameters and runs them depending on the parse stage for input data. this is the code that I wrote: #include enum class ParseState { …
1
vote
1 answer

Variadic template parameter with variadic constraint

I have a template-head of the form template... U>, where C is a concept and T is a pack of types. U will have to be its own pack, but how exactly is this parsed? For example https://godbolt.org/z/MhG9YqsdK: #include…
Artyer
  • 31,034
  • 3
  • 47
  • 75
1
vote
1 answer

Uninitialized variable using IIFE and fold expression in C++

I was playing around with IIFE's and parameter packs in MSVC C++20 when I stumbled across a strange error. The following code is a minimal reproducible example. #include #include template struct Foo { …
BubLblckZ
  • 434
  • 4
  • 14
1
vote
1 answer

Parameters pack with single function

Below code extracts n-th argument of function formatted as string. How can I implement it without providing the second function? Is it possible at all? template static std::string getArgument(unsigned argumentIndex,…
no one special
  • 1,608
  • 13
  • 32
1
vote
1 answer

Can I generalize this set of functions into one that takes a variable length argument list (e.g. by using a parameter pack)

I want to know if there is a way to generalize this set of functions into one that takes an arbitrary number of arguments. The specifics of Var and LetN shouldn't be needed here. (This is from some expression template building code. LetN creates a…
asynth
  • 214
  • 2
  • 8