Questions tagged [parameter-pack]

171 questions
1
vote
2 answers

c++ Extract parameter type list from function pointer

Im trying to get the argument types from a function pointer This should be the working end product std::function::InputArgs)> func = &TestAppObject::TestMethod; Current…
1
vote
3 answers

How can one construct an object from a parameter pack in a C++ template?

Given the following, how can I correctly construct an object of an unknown type from a parameter pack? template < typename... Types > auto foo( Types&&... types ) { auto result = Types{ }; // How should this be done? // Do stuff with…
cbrng
  • 63
  • 4
1
vote
3 answers

Can multiple parameter packs be expanded in a single expression?

I want to get a matrix from two parameter packs like the following: template < typename T1, typename T2 > struct Multi{}; template < int ... n > struct N{}; void Print( int n ){ std::cout << n << std::endl; } template < int ... n1, int ... n2…
Klaus
  • 24,205
  • 7
  • 58
  • 113
1
vote
1 answer

Why does passing a parameter pack to a function with one template parameter call it multiple times?

Take this code: template int foo() { std::cout << "foo called" << std::endl; return 10; }; template std::vector bar(Ts... ts) { std::vector vec{foo()...}; return vec; }; int main() { …
JensB
  • 839
  • 4
  • 19
1
vote
1 answer

Arrays of Objects without standard constructor using Parameter Packs

I want to fill an std::array of size N with objects without a standard constructor. std::array myArray; (It's std::array, 64> in my case, to be specific) This results in the error error: use of deleted function ...…
SpiRelli
  • 88
  • 6
1
vote
1 answer

default template argument and parameter pack

In a classic recursive template specialization I need one type multiple times in the class definition, e.g. for inheriting and using statement, maybe on other places also. Example: template < typename ... T > class C; template < typename FIRST,…
Klaus
  • 24,205
  • 7
  • 58
  • 113
1
vote
1 answer

Strange error while expanding parameter pack containing lambda types

I have a function which looks like foo in the following example: template void foo(std::function... functions) { // does interesting things with these functions } Now I want to call this function…
Josef Zoller
  • 921
  • 2
  • 8
  • 24
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
1
vote
1 answer

How to improve some variadic parameter pack template implementation

I have managed to make a library to help me making request to SqlLite library, specially those related with BLOB files. The problem came because I feel that the implementation can be improved, but I do not have enought knoledge to achieve it. Any…
Pablo
  • 557
  • 3
  • 16
1
vote
1 answer

Create C-style array form parameter pack

How can I create an array from the parameter pack? template void covert(Tpack ...pack){ T *arr = new T[???]; //TODO: how to get Tpack size? // TODO: how to fill array? }
sergej.p
  • 85
  • 1
  • 5
1
vote
3 answers

Compare memberwise parameter packs of different lengths

template struct type {}; template struct are_compatibles; template struct are_compatibles, type> : public…
alex-dev
  • 13
  • 4
1
vote
2 answers

parameter packs parameter type

I have modified the sample from https://en.cppreference.com/w/cpp/language/parameter_pack to save the string in a variable. My code #include void tprintf(std::string& str, const std::string& format) { str += format; } template…
1
vote
0 answers

Undefined reference to static constexpr, if passed as function parameter pack with O0 (works with higher optimization levels)

The following code snippet can only be linked if optimization level was higher than O0: #include #include void vf(std::size_t n, ...) {printf("%zu\n", n);} template void vt(ARGS&&... args) {vf(…
1
vote
3 answers

Expand parameter pack into tuple with tuple_cat

Godbolt link: https://godbolt.org/z/18nseEn4G I have a std::map of various types of vectors (cast to void*) and a T& get method that gives me a reference to an element in one of the vectors in the map. class Container { public: Container() { …
Acorn
  • 1,147
  • 12
  • 27
1
vote
1 answer

How can I implement a constexpr N-way set_union (deduplicated merge)

I have a bunch of structs holding pre-sorted std::arrays of varying number of size_ts. As a toy example, suppose we've got the following three structs: struct F_A { static constexpr std::array bounds = { 0, 100, 200, 300 }; }; struct F_B…