Skip to main content
Filter by
Sorted by
Tagged with
6 votes
2 answers
168 views

Function templates and class templates with non-type template parameters differ when instantiated with an empty parameter pack of types

I have the following program with a function template and a class template, both of which have a non-type template parameter. If I try to pass an empty parameter pack of types to the class template, ...
Bob liao's user avatar
  • 701
5 votes
2 answers
116 views

How can I make a tuple of types that can be accessed by index without pack indexing?

Using C++26's pack indexing, you can create a simple tuple of types like so: template <typename... Ts> struct type_tuple { template <unsigned Index> using get = Ts...[Index]; }; ...
HeliumHydride's user avatar
0 votes
2 answers
81 views

How to pass parameter pack by reference and pointer?

How to pass parameters to a function by reference and through a pointer? I have an example in which I try to call one of two write functions of the CFoo class. The example compiles if I specify two &...
Daniel's user avatar
  • 5
3 votes
0 answers
75 views

Why does constrained template function declaration with template parameter pack not compile when constraint has extra template parameter before pack?

I tried to write a generalized version of std::same_as that needs to work with any positive number of type arguments. I wrote the following concept, keeping the first template parameter separate from ...
Bernard's user avatar
  • 5,650
5 votes
1 answer
103 views

No concept subsumption with template parameter pack?

In C++20, concept subsumption refers to a concept being a superset of another concept. For example, in the following example, Fooable subsumes BetterFooable: template <typename T> concept ...
Bernard's user avatar
  • 5,650
6 votes
3 answers
205 views

Parameter pack to initialize member std::array

I have a class Color which is a thin wrapper around std::array. I would like to be able to use it in 2 ways: Color<5> color{1,2,3,4,5} should produce color.values = [1,2,3,4,5] Color<5> ...
Chris Gnam's user avatar
4 votes
2 answers
84 views

Partial template specialization for when all template parameters are the same type

Is it possible in C++14 (so no constraints, require or fold expressions, but there is SFINAE) to have a partial template specialization of a class template template <typename ...T> class Generic ...
Daniel Varga's user avatar
3 votes
0 answers
74 views

Unpack the first N-1 elements of a parameter pack [duplicate]

template <typename... Args> auto foo(Args&&... args) { // N = sizeof...(args) // need args[0], args[1] ..., args[N-2] as tuple and/or forward them } I have C++20 at my ...
Juergen's user avatar
  • 3,733
1 vote
2 answers
133 views

How to interleave C++ template parameter packs

I have this c++ template function template <int N, int B, auto... Args> void somefunc() { // do work... } , which I can call like this: somefunc<1, true, 2, false>(); I want to ...
lobelk's user avatar
  • 323
3 votes
1 answer
46 views

How does a Swift parameter pack solve the stated motivational problem?

The Swift evolution parameter packs proposal begins with a Motivation section that cites the following bit of familar ugliness: func < (lhs: (), rhs: ()) -> Bool func < <A, B>(lhs: (A, ...
matt's user avatar
  • 534k
0 votes
1 answer
35 views

Use parameter pack to initialize map of templated

For a class that looks like this: class A { public: template <int X> void foo(double param); const std::map<int, std::function<void(double)>> foo_map; }; Where foo_map ...
user1470475's user avatar
1 vote
1 answer
60 views

Const-qualifier lost on variadic template parameter when trying to pretty-print function signature [duplicate]

I wish to use template programming with type traits to pretty-print the signature of a function. While the gist of what I came up with works, the const-qualifier on the function arguments is dropped. ...
Donald Ninetyfive's user avatar
1 vote
1 answer
51 views

deduced conflicting types for parameter 'T' (<const int &> vs. <int>)

I have a class Base and MyFunc templates with parameter packs. I have a class Derived, which specifies a const T& type in the parameter pack. template <typename... T> class Base {}; ...
Nick Golob's user avatar
1 vote
2 answers
93 views

How to pairwise iterate over a type list and value list

I've got a typelist like template <typename ...Types> struct type_list {}; and am looking for a way to iterate over pairs of elements from that type list and some value list from within a ...
ridilculous's user avatar
1 vote
1 answer
38 views

expand and fold parameter pack in specific way

#include <string> #include <string_view> template<typename... Args> std::string_view concatenateBuffer(std::string &buffer, Args &&... args){ static_assert((std::...
Nick's user avatar
  • 10.5k
0 votes
2 answers
174 views

Packing, unpacking and storing parameter pack in a tuple

I have a function pointer and parameters, and I'd like to save these and potentially modify them and call the function with them. I've seen parts of this answered however I'm unsure how a complete ...
LemonJumps's user avatar
3 votes
2 answers
212 views

Swift parameter packs and Sendable

The following code produces a warning about a non-sendable type: func pack<each U: Sendable>(arg: repeat each U, function: @escaping @Sendable (repeat each U) -> Void) { Task { @MainActor ...
Sergey A. Novitsky's user avatar
1 vote
1 answer
87 views

How to print the line number of the caller function from a template function?

I am implementing a log function which logs along with line number of the code. The snippet of the code as follows: #include <iostream> using namespace std; char m_buffer[500]; template<...
GShaik's user avatar
  • 311
0 votes
0 answers
20 views

Inconsistency between g++ and clang++ on template parameter pack deduction

I found the following minimal example when experimenting metaprogramming: #include <iostream> #include <utility> #include <tuple> template <size_t ...Is> void print(const std::...
jinzx10's user avatar
  • 33
0 votes
1 answer
42 views

Creating a std::array of templated functions results based on the types of a tuples elements

I want to create an array where each element is (at runtime) calculated based on the type of each element of a Tuple. In practice I want to assign a runtime id to each type that exists in a tuple by ...
bonkt's user avatar
  • 17
1 vote
2 answers
89 views

Transforming Parameter pack in template without wrapping struct

I have the following code, which works: template <typename ...Types> struct Wrapper { template <void (*F)(typename Types::ParameterType...)> static void toNativeFunction(Stuff ...
Francisco Ryan Tolmasky I's user avatar
1 vote
0 answers
47 views

Proper usage of Comma fold in parameter pack C++

I have a class with a variadic argument templated constructor and I am trying to separate out the parameter pack one by one and pass it to member set function. I tried std::move and std::forward as ...
Nitron_707's user avatar
0 votes
0 answers
38 views

C++: Prevent method from expanding too early when passed as argument

I attempt to write a basic logger that should pass any message to the shell and a log file (for now, both write to std::out) using std::vformat. For that, i created a wrapper log_message(): template &...
Lupino's user avatar
  • 154
1 vote
1 answer
485 views

std::print() and template parameter pack

Would be possible to print a template parameter pack using std::print? something like: void func(auto... args){ std::print("???", args...); } EDIT: if it wasn't clear: "???" ...
Solo's user avatar
  • 409
1 vote
0 answers
176 views

Swift store closure with parameter packs

I would like to create a closure type that is always called on the main thread using the new parameter packs introduced in Swift 5.9. E.g. protocol Repository { func loadData(completion: ...
Guy Kogus's user avatar
1 vote
0 answers
115 views

Pass a List to a Function to act as Multiple Arguments in C++ [duplicate]

In Python, we can unpack a list to pass the elements of the list as arguments to a function. I am looking for a similar feature in C++. I have a list of unknown size and a function which has number of ...
Ricky Dev's user avatar
1 vote
1 answer
349 views

Variadic Generics vs. Value and Type Parameter Packs in Swift

There are two evolution proposals: Variadic Generics and Value and Type Parameter Packs. So... what is the difference? They feel conceptually very similar. The second one, with super heavy syntax, is ...
Roman's user avatar
  • 1,488
0 votes
1 answer
96 views

correct order in template parameter pack expansion

I want to fill a tuple<Ts...> from a vector of variants. (NB: This question follows up on Creating a tuple from a folding expression return values , see 2nd comment to the answer ) Expanding the ...
kaba's user avatar
  • 477
0 votes
0 answers
76 views

ExpressibleBy#Literal with parameter pack "Cannot convert value of type '#ExpressibleType' to expected argument type '#Type'"

I'm trying to create a generic function to apply some image filters. The applyFilters(_:) function uses Parameter Pack of ImageFilter. Calling applyFilters(_:) with static functions that take a type ...
m_sh's user avatar
  • 1
7 votes
1 answer
399 views

std::type_identity to support several variadic argument lists

std::type_identity can be used to provide non-deducible context. So, I wondered if it will work on a deduced variadic list. But different compilers give different results. https://godbolt.org/z/...
Sergey Kolesnik's user avatar
2 votes
2 answers
68 views

How to create a stack ND C-array from param pack of length N?

For the parameter pack size_t ...len, e.g. [len={3,5,2}, I wish to create double x[3][5][2]; or an equivalent type that I can reference to it (cf Requirement below). Question Is there a short way of ...
mhawth36's user avatar
4 votes
3 answers
204 views

How to generate parameter packs via meta-programming?

Suppose template<T,typename... Types> void bar(Types..., int,Types...,float,T); I am trying to write a template struct GimmePack<double,k> so that bar<char, GimmePack<double,3>::...
mhawth36's user avatar
0 votes
1 answer
125 views

How to deduce parameter-pack from brace-enclosed initializer list? [duplicate]

This is a convenience question. I have a valid implementation of FooImp< Aux<int...>, Aux<int...> > in the namespace FooDom when both int... parameter packs are of same length. My ...
mhawth36's user avatar
0 votes
2 answers
91 views

Accessing index in parameter pack during template substitution

I have a template function in C++17, where the N first arguments need to be integral type, and this should be checked during template substitution. (The template function should not exists for ...
tmlen's user avatar
  • 9,042
7 votes
1 answer
183 views

Is TemplatePack<>...[I] allowed in C++26

Pack indexing was introduced in C++26 and I was hoping for this feature to have a significant impact on metaprogramming stuff, especially for indexing packs which would otherwise require workarounds. ...
Desmond Gold's user avatar
  • 2,045
0 votes
2 answers
98 views

Is it possible to define a method overload for each element of a template parameter pack?

Suppose I have a class template with a type template parameter pack, like template<typename... types> class Foo {}; Is there any way I could define methods in Foo, say void bar(T x); with ...
Nick Matteo's user avatar
  • 4,553
1 vote
1 answer
80 views

Parameter pack in overload resolution

Consider the following code: template<class T> void f(const T& a, const T&b) { std::cout << "#1"; } template<class ...T> void f(T&& ...a) { std::cout <&...
Elucidase's user avatar
-1 votes
2 answers
239 views

error C3856: 'RecursiveType': symbol is not a class template [duplicate]

I am trying to create type with recursive template like std::tuple, unfortunately it does not compile, however I did it seemingly same way as in tuple source code. I am compiling with Visual Studio ...
Somnium's user avatar
  • 1,125
3 votes
2 answers
80 views

Is there a less verbose way to initialize a tuple of heterogenous tuples (or similarly templated types)

I'm wanting to construct a tuple of hetergenous tuples but this seemingly requires an explicit constructor call for each member: auto foo = std::tuple{ std::tuple{1, "foo", 3}, std::...
TooZni's user avatar
  • 133
2 votes
2 answers
455 views

How to create a variadic ZipSequence type with Swift's parameter packs?

According to SE-0398, we can now create types with a variable number of generic type parameters. The document uses ZipSequence as an example: In the generic parameter list of a generic type, the each ...
Sweeper's user avatar
  • 266k
2 votes
1 answer
81 views

Resolve Template Parameter Pack Overload Ambiguity

Minimum Example I have the following struct with a few specializations: template<size_t ...Tpar> struct Base{}; struct X{}; struct Y{}; template<typename T, size_t ...Tpar> struct Spline:...
kaisong's user avatar
  • 171
0 votes
1 answer
50 views

How do I best implement a Derived with members depending on a Template Parameter Pack Specialization?

Goal I want to implement a struct Derived<size_t ...Tpar>, satisfying certain requirements. I have a functioning solution code, but it has certain disadvantages. I seek a better way of doing it. ...
kaisong's user avatar
  • 171
0 votes
1 answer
160 views

using c++20 concepts to find nth element of parameter pack [duplicate]

I am looking for a non-recursive, modern method (which compiles, at least with gcc and clang) for finding the 𝑛th element of a variadic parameter pack. Indeed, it would seem such a solution, using c++...
phoko's user avatar
  • 1
2 votes
1 answer
1k views

Is it possible to iterate over the arguments of a Swift parameter pack?

Parameter packs are a cool new feature of Swift 5.9, but surprisingly there doesn't seem to be a lot of discussion about them, and I hadn't seen this question answered on StackOverflow.
Gregory Higley's user avatar
2 votes
1 answer
814 views

Swift 5.9: Parameter Packs getting Pack reference 'each V' can only appear in pack expansion

Hi Im trying to use the new variadic generic feature of swift 5.9. So I have a code that Im trying to refactor it: func resolve<T>() -> T { // Resolve method } func autoResolve<T>(_ ...
Mickael Belhassen's user avatar
0 votes
1 answer
157 views

Simplify creation of compile-time binary tree type

In the context of creating a binary tree type for a larger C++ project, I need to create a compile time type representing the nodes in each level. Does anyone know, using the newest standards, if ...
Astor's user avatar
  • 394
2 votes
1 answer
1k views

How to use Swift parameter packs in a View

I want to easily provide mutable bindings to my views for SwiftUI previews (so that the preview is interactive unlike when you pass a .constant(...) binding). I followed the BindingProvider approach ...
Trev14's user avatar
  • 4,106
0 votes
2 answers
82 views

definition dependent template deduction failure

Within a larger project I got issues when trying to use templates to define multiple classes. After some tinkering I found out, that my code was working when I changed the order of the template ...
wodtko's user avatar
  • 3
1 vote
1 answer
107 views

Use parameter pack in template parameters list

I want to write an abstract Pipeline class that gets some functions with a specific signature as template parameters and runs them depending on the parse stage for input data. this is the code that I ...
Amir Hossein Sarebani's user avatar
-4 votes
2 answers
84 views

Why I can't use parameter pack in the constructor

Here is my code in hpp: template <size_t... Bits> class TelemetryCompactDataStrategy : public TelemetryCommonDataStrategy { static_assert((Bits + ...) <= 32, "Bit count must not ...
wcc chn's user avatar

1
2 3 4 5