Questions tagged [parameter-pack]
171 questions
0
votes
2 answers
Validating std::function with variadic args against a 'kind' hierarchy
I have a system (C++14, using Visual Studio 2015 & GCC 4.9.2) where we have a number of different kinds of 'events' that can cause a callback to occur, and a hierarchy of classes which identify the kind of event and other custom properties specific…

Danny S
- 457
- 4
- 15
0
votes
1 answer
Using a parameter pack to generate objects
I am looking to create an object that can instantiate a class on command. The reason why I want to do it like this, is because I have to create instances of an object, that all have the same initial parameters read from a file, but I want to load…

Lala5th
- 1,137
- 7
- 18
0
votes
1 answer
Iterate over parameter pack of types
I'm trying to simplify usage of pybind11 when binding templates.
For now I have a parameter pack of types and I need to call a function cl.def() (look at the code below) with each type from that parameter pack. Also there is a vector of names and…

Kerim
- 171
- 3
- 10
0
votes
1 answer
How do I stop this templated function value-initializing a new constructed object?
If I can a parameter pack for the constructor arguments when I create a new object and I don't provide any constructor arguments then the result will be: new T(); which will value-initialize the object if it doesn't have a user-provided constructor.…

Zebrafish
- 11,682
- 3
- 43
- 119
0
votes
1 answer
Using variadic template arguments for arbitrary number of classes
I have a situation where I need a class FaceProp that maintains/holds other classes for actual face types. These could be any types of faces like boundary faces, solid faces, internal faces etc etc. I wanted to implement FaceProp using the variadic…

ATK
- 1,296
- 10
- 26
0
votes
0 answers
Passing parameter packs to a template with parameter non-pack and parameter-pack
The following code is an error in GCC trunk and Clang trunk:
https://godbolt.org/z/YYzdeh
#include
template typename Container,
typename Type,
typename ... More>
struct Contain
{
using type…

Arjonais
- 563
- 2
- 17
0
votes
1 answer
unpack multiple parameter packs to initialize a 2d array
I'm trying to unpack multiple parameter packs so that arr[i][j] = X(i,j). However I get the following error with the current approach below. Are there approaches to achieve the above using C++14/17?
// Non copyable and default constructable
struct…

user3882729
- 1,339
- 8
- 11
0
votes
1 answer
Variadic template function specialization in a template class
I am trying to implement an own SmartPointer class and after an initial working version I have started to refine the code and now facing an issue, that I am unable to resolve.
Here is the first version:
template
class…

Sándor Megyeri
- 43
- 7
0
votes
2 answers
Pass data via template argument, C++
I am thinking about having color spaces structs in my program. Now as you can see each color space has its limitations for each of its component. So consider a struct like this.
template
struct SomeColorSpace{
T…

Hrant Nurijanyan
- 789
- 2
- 9
- 26
0
votes
1 answer
C++ parameter pack access out of range
I'm kinda new to parameter pack and I ran into a problem related to out of range index. To simplify the problem, I want to access the n-th element (lets say 3rd) in parameter pack inside the function. If the function call does not pass 3 params (or…
0
votes
1 answer
Construct a tuple with arbitrary number of types, all constructable from a single type, and non-default-construcible
I have a tuple
using MyTuple = std::tuple;
and want to construct MyTuple like this
MyTuple foo{Foo1{x}, Foo2{x}, Foo3{x}, ... FooN{x}};
FooK is not default constructible
N is not known at write-time. Thus I cannot…

user877329
- 6,717
- 8
- 46
- 88
0
votes
0 answers
CTAD and template constructor with member with parameter pack
Trying to use universal references with CTAD and parameter pack I tried something like below, but it doesn't compile on MinGW GCC. And I don't understand why.
This is the sample code:
#include
template
struct Subtest
{
…

Andrei
- 360
- 2
- 9
0
votes
1 answer
Initializer list, parameter pack expansion, fold expressions and order of evaluation
I have the following code to address a n-dimensional tensor class (offset is a std::vector of std::size_t):
template
double Tensor::at(int first, Ts... others) {
int i = 0;
std::size_t index =…

ptrchv
- 55
- 5
0
votes
1 answer
extracting a template parameter pack with different types into a vector of doubles produces warnings
I am trying to convert a load of classes that are basically the same but take different number of parameters into a single template class. So I have create a template class example (not real code - just for example):
// The template…

code_fodder
- 15,263
- 17
- 90
- 167
0
votes
1 answer
How to expand parameter pack pattern in an "unzipping" manner?
Say I have a variadic function, foo:
template
void foo(Args... args)
{
// some work
}
I want to have a magic function, bar, that forwards its arguments to foo in the following manner:
Say if I call
bar(x, y, z);
It'll have…

Hank
- 310
- 1
- 5