218 questions
6
votes
2
answers
175
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, ...
5
votes
2
answers
121
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];
};
...
0
votes
2
answers
82
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 &...
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 ...
5
votes
1
answer
105
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 ...
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> ...
4
votes
2
answers
85
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 ...
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 ...
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 ...
3
votes
1
answer
48
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, ...
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 ...
1
vote
1
answer
62
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. ...
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 {};
...
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 ...
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::...