Questions tagged [parameter-pack]

171 questions
1
vote
1 answer

May I implement this function with a parameter pack?

template typename ... tys_str ↑ I cant define the parameter pack to express that paramater pack is constrainted to basic_string classes with a template argument */ > void concat_strings(…
Boma Kim
  • 33
  • 5
1
vote
0 answers

Parameter pack within template class constructor throws unexpected end-of-file found (C1004)

I have a template function that works okay by itself: // some_util_file.h namespace ArgsUtil { struct Args { void* item; Args* next{ nullptr }; }; template static void…
Froppy
  • 11
  • 2
1
vote
0 answers

Add members at compile time without copy/move constructors

I'm learning about Variadic Template and Fold Expression. I would like to avoid the use of dynamic allocation and pointers. To illustrate my problem, I created the Foo (copy and move constructors are deleted) class which inherits from I_Foo. class…
1
vote
2 answers

Generate a sequence of null values follwed by one at compiletime

I have a problem similar to Generating a sequence of zeros at compile time However, in my case I have no pack to expand. The situation is like this: template void foo() { bar(T{}, ..., static_cast(1)); } There are N - 1 T{}:s followed…
user877329
  • 6,717
  • 8
  • 46
  • 88
1
vote
1 answer

How to defer expanding a parameter pack?

I was toying around with tuples. I wanted to zip an arbitrary number of tuples. There is probably a better way to do that than what I came up with, but my solution led me to a problem that is interesting in itself. Sometimes, you want to expand one…
1
vote
1 answer

Is there a way for a class template to deduce the size of a parameter pack passed to the constructor?

If I have a class template like such: template struct foo { template... Ts> foo(Ts... ts); } Is there any way whatsoever to deduce the template parameter N from the size of the parameter pack passed to…
JensB
  • 839
  • 4
  • 19
1
vote
3 answers

Create string according to the parameter pack arguments count

I have a function with a parameter pack, I pass this pack to the fmt::format function, and I want to create a formatStr according to the args count, meaning add "{}#" for each passed argument. I can do it using iterating, but is it possible to do…
Hardwired
  • 804
  • 1
  • 8
  • 19
1
vote
5 answers

Slice parameter pack parameters

I would like to split a parameter pack in all the first and one last parameter, but C++ requires the parameter pack be the last in the function declaration, so this is not valid code. template void func( Ts... args,…
Generic Name
  • 1,083
  • 1
  • 12
  • 19
1
vote
1 answer

Why does the compiler issue a template recursion error?

I'm currently trying to deduce a std::tuple type from several std::vectors that are passed as parameters. My code works fine using gcc, but the compilation fails with Visual Studio Professional 2019 with the message "fatal error C1202: recursive…
1
vote
0 answers

C++ "fatal error C1202: recursive type or function dependency context too complex" in visual studio, but gcc compiles

Edit2: I rephrased the question and asked specifically, where the template recursion occurs in this question: Why does the compiler issue a template recursion error?. There, it turned out that problem is actually not related to my code, but…
1
vote
1 answer

Nested initializer lists

I am making an attempt in creating dynamic Python-like dicts in C++. One possible approach to implementation (which has its drawbacks, for sure) is #include #include #include using namespace std; class dict; using Atom =…
Mike Land
  • 436
  • 4
  • 15
1
vote
0 answers

Check template parameter pack for specific values

I am writing a small Tensor class, that should look like this: using namespace std; // for simplicity template class Tensor { size_t rank_; array size_; vector data; public: template
Urwald
  • 343
  • 1
  • 10
1
vote
2 answers

Enumerating a pack

I don't quite understand the base trick from Daisy Hollman's talk: https://youtu.be/15etE6WcvBY?t=2670 Enumerating a pack using c++20 lamdas with explicit template arguments. #include #include template
Oliver Schönrock
  • 1,038
  • 6
  • 11
1
vote
2 answers

Metafunction to check if all parameter pack arguments are the same

I'm new to template metaprogramming. I was looking for a metafunction to check if parameter pack arguments are of a certain type (C++11 required). For this I use: template void foo(Ts... args) { static_assert(is_all_same
glades
  • 3,778
  • 1
  • 12
  • 34
1
vote
2 answers

How to expand the initializer list parameters pack?

Codes like: template void print(type... pack) { ((std::cout << pack << " "), ...); } But I have parameters like: { {1, 2, 3}, {4, 5, 6} } So how can I pass this to the function ? Or, how to expand the parameters pack like…
iEcho-42
  • 137
  • 1
  • 7