Questions tagged [parameter-pack]
171 questions
0
votes
1 answer
Why does pack expansion allow to constrain template-dependent types but not regular types?
Compare the invocation of foo() and bar() with an arbitrary amount of arguments. I can call bar() and constrain the parameter type to B but just in the case I equip B with a parameter pack. If I don't (like in A), gcc doesn't allow me to specify the…

glades
- 3,778
- 1
- 12
- 34
0
votes
1 answer
How to pass a template function to another function and apply it
// I can't change this function!
template
void RpcWriteKafka(Function func, Args&&... args) {
func(std::forward(args)...);
}
// I can change this one if necessary.
template

Yves
- 11,597
- 17
- 83
- 180
0
votes
2 answers
Creating function to read variables from file into variable quantity of parameters
How would I create a function that can read values from a file into multiple numbers of variables varying from 1 to many?
Here's what I have so far, working from a similar question.
Note: I cannot use fold expressions (file >> ... >>> x) because the…

wand_swe
- 43
- 5
0
votes
3 answers
C++ 17 Expand a Fold Expression (as pairs of values)
I am writing some code to experiment with fold expressions.
I don't think my approach to solving this problem is the best possible approach.
I am trying to write a function which "does something" with pairs of values obtained from expanding a…

FreelanceConsultant
- 13,167
- 27
- 115
- 225
0
votes
0 answers
Adjust array inside struct according to parameter pack length (passed into constructor)
I want to create a constexpr struct which holds a number of states in an array, represented by state_type_t. The struct should be created dynamically via a parameter pack. My problem is that I don't know the size of the array holding the states as I…

glades
- 3,778
- 1
- 12
- 34
0
votes
1 answer
Pass parameter pack to function repeatedly
I need to pass a parameter pack to a function repeatedly in a loop, like this:
void printString(string str)
{
cout << "The string is: \"" << str << "\"" << endl;
}
template
void RunWithArgs(FunctionType…

TS_
- 75
- 4
0
votes
1 answer
Pass a variable number of arguments into a function
I know how to use variadic templates and ellipses to accept a variable number of arguments, but how do you pass a variable number of arguments into a function?
Take the following code for example:
#include
struct A {
A(int a, int b) :…

Gary Fisher
- 79
- 7
0
votes
2 answers
Generate Integer Sequence For Template Parameter Pack
There is a class method template with parameter pack I want to call, defined as:
class C {
template void function() {}
}
For a given integer N, I need all integers up to N as template arguments for the parameter pack.
constexpr int…

lando
- 23
- 4
0
votes
1 answer
How to extract requires clause with two parameter packs into a concept?
I have this (supposedly not so useful) class template with templated constructor which is a candidate for perfect forwarding. I, however, wanted to make sure that the types passed to the constructor are the exact same as the ones specified for the…

Fureeish
- 12,533
- 4
- 32
- 62
0
votes
1 answer
Is there a way to expand the scoped types of variadic template parameters in a parameter pack in c++?
I would like to enforce that all types in a parameter pack have a nested type alias declared in them (T), and expand all the T's of the types into a tuple. Is something like this possible? When I try the naiive way below, it doesn't recognize…

Kyle Beyer
- 21
- 2
0
votes
2 answers
Parameter pack extraction
I have a function2, which can be called with or without a second argument == char.
If so, I want to modify that char-Argument.
Given
void function1_caller(int x) {
char ws=7;
function2_modifyArg(x, ws);
}
This works:
template

GGeorge
- 3
- 2
0
votes
0 answers
Acces parameters in parameter pack in c++
How to acces each parameter in parameter pack?
I have a function delcaration in my main executable, but the function body is in other library
template
some_class* foo (Types ... args){
//cast args to var1, var2, var3 somehow
…
0
votes
1 answer
When is an ellipsis needed when dealing with parameter packs?
I'm trying to understand some code from cppreference.com. The relevant part is here
template
std::ostream& operator<<(std::ostream& os, std::tuple const& theTuple)
{
std::apply
(
[&os](Ts const&... tupleArgs)
…

jwezorek
- 8,592
- 1
- 29
- 46
0
votes
0 answers
Enum extending with template parameter pack
Here is instruction to create enum extending behavior. I have implemented it like this:
inheritenum.h:
template
class InheritEnum{
public:
InheritEnum() {}
InheritEnum(EnumT e):…

Aryan Firouzian
- 1,940
- 5
- 27
- 41
0
votes
1 answer
affect of constexpr on Parameter pack
Why is this code invalid without constexpr:
template
auto CalculateSum(Tpack ...pack)
{
if constexpr (sizeof...(Tpack) > 0)
return (pack + ...);
else
return 0;
}
int main()
{
std::cout << CalculateSum(2,…

Max Popov
- 357
- 2
- 12