Questions tagged [parameter-pack]

171 questions
2
votes
1 answer

Mapping constexpr class static to the class for a collection of classes

I have an extendable collection of classes that have approximately the same interface, that each have a different static constant for serialization purposes. Consider: class A { constexpr static int value = 0; }; class B { constexpr static…
Mark
  • 31
  • 4
2
votes
1 answer

How can I constrain one template's variadic 'type-parameters' with various specializations of some certain second template in C++?

I need to have a template struct Lists, whose variadic parameters can only be the types represented by specializations of some certain container template List. Different Lists instances should be able to depend on different (but fixed for one…
soad
  • 49
  • 6
2
votes
1 answer

How to ignore parameter pack arguments

With the expression (void)var; we can effectively disable unused variable warnings. However, how does that work with arguments in a parameter pack? template void log_debug(const Arg&... args) { if…
Raildex
  • 3,406
  • 1
  • 18
  • 42
2
votes
3 answers

c++11 expanding parameter pack inside of a lambda

I'm trying to assign a lambda to my std::function that contains 1 call to Test for each type specified in the parameter pack, does anyone know how to do this? template void Test() { } template void Expand() { …
David Carpenter
  • 1,389
  • 2
  • 16
  • 29
2
votes
0 answers

What does "instantiating a pack expansion" mean?

I get confused when I encounter this sentence (bold) from the standard - [temp.deduct]/11: [ Note: Type deduction may fail for the following reasons: (11.1) Attempting to instantiate a pack expansion containing multiple packs of differing…
mada
  • 1,646
  • 1
  • 15
2
votes
1 answer

Parameter pack constructor preferred over other constructor calls

Consider a constructor accepting a parameter pack, such as template consteval explicit foo(const First& first, const Rest... rest) : arrayMember{first, rest...} { } where First and Rest... all…
2
votes
2 answers

How to expand multiple index_sequence parameter packs to initialize 2d array in C++?

I'm trying to initialize my Matrix class with std::initializer_lists. I know I can do it with std::index_sequence, but I don't know how to expand them in one statement. This is how I do it: template class Matrix { public: …
sshd
  • 49
  • 1
  • 4
2
votes
0 answers

GCC and MSVC complaints about getting the last element from the parameter pack?

I was basically looking into the talk: https://youtu.be/15etE6WcvBY?t=3315 Despite the typo in her shown code, I tried myself the code for better understanding. However MSVC and GCC was not happy to accept the code and the Clang does:…
Const
  • 1,306
  • 1
  • 10
  • 26
2
votes
1 answer

Override parameter pack declaration and expansion loci

I have a simple interface setter: template struct FrontEnd { virtual void inject(Interface*& ptr, Client* client) = 0; } I want to implement these interfaces through parameter packs like this: template struct…
lurscher
  • 25,930
  • 29
  • 122
  • 185
2
votes
3 answers

Unpacking first parameter from template parameter pack c++

I'm new with templates, specially with parameter pack and I wonder if I can get the first value from the pack. For example the following code: template bool register(Args... args) { if (!Foo(args..) { …
Idan Cohen
  • 125
  • 1
  • 6
2
votes
3 answers

Print method for variadic template pairs in C++

I want to achieve something like: export_vars("path/to/file.dat", {"variable_name", obj}, {"another_variable", 2}); where obj can be any type as long as it has an << overload - the idea is to write to an ofstream later on. I have tried (for an…
Androvich
  • 1,030
  • 1
  • 7
  • 11
2
votes
1 answer

How to correctly capture parameter pack in std function lambda c++ 11

I have been trying to capture some parameter pack parameters within std function lambda, in order to save functions in memory for future use. However, in some cases, where any of the values from these captured parameters are modified after having…
Samuel
  • 816
  • 1
  • 7
  • 13
2
votes
0 answers

Keyword for both types and integrals for parameter packs

If I have a trait that detects a specialisation (i.e. a templated type): template struct is_specialisation : std::false_type { }; template