2,426 questions
0
votes
1
answer
191
views
Typename packing is failed in C++
Here is code:
aml::type_list<int,int,char,std::string> example;
std::tuple_element_t<2,std::tuple<decltype(example)>> a = 'b';
But when i try to run code it says, static assertion ...
1
vote
1
answer
128
views
Why template instantiation requires specialation in the case where it is already done for all cases?
In c++ when i try to write a code that returns reverse of a type list what i wrote( a user defined template class):
template <typename ...V,typename ...D>
constexpr decltype(auto) merge(...
0
votes
2
answers
218
views
C++ check if const qualified variables are the same object at compile-time
I am working on a project that uses some compile-time logic based on whether two arguments are the same object (i.e. same memory address). The following is a simplified example that compiles and runs ...
1
vote
1
answer
128
views
What is explanation/fix for compiler's error when sorting types of tuple using decltype, lambdas and std::array?
I needed to sort types in a tuple by alignment, and as a result I just want to get a new tuple type.
Wrote some implementation. But in one case (when using consteval auto sort_tuple(auto tuple)) gcc ...
2
votes
2
answers
128
views
Deduce maximum number of function arguments (fails with concepts)
I am writing a function probeMaxArgs that deduces the maximum number of arguments in a function/callable object. For simplicity I assume, that the object don't have any overloads of operator() (...
4
votes
0
answers
246
views
Compile-Time Type Registry in C++
I need a way to set up a compile-time "registry" that maps registered types to incrementing int IDs and back again.
I would prefer it to be implemented such that, when used, the library to ...
0
votes
1
answer
83
views
Compile‑time conversion of a JSON literal into a JsonString<char…> type in C++20 – overall design patterns? [closed]
I’m exploring ways in C++20 to represent a JSON text literal entirely in the type system, so that I can then write a metafunction like
template<typename Json, char... Key> struct HasKey;
...
3
votes
0
answers
151
views
Why does C++26 still not allow passing a function template as a template parameter?
In C++26, the following code is legal (see p2841r7 and Herb Sutter's article):
template<typename<typename> concept C, template<typename> auto vt, typename T>
requires C<T>
auto ...
3
votes
2
answers
233
views
C++ template metaprogramming - selecting a range of arguments from a parameter pack
I am making a compile time ECS system and have created an archetype class to store components:
template<typename... Components>
class Archetype;
template<typename T>
struct ...
5
votes
1
answer
204
views
Are structured binding packs allowed in expansion statements outside of template?
Recently, expansion statements have been accepted to C++26 draft. Which means, this gives us another way of iterating through members of destructurable types such as "Point" defined below.
...
9
votes
3
answers
945
views
How to constrain a C++ template template argument to be a child of a templated type?
In the snippet below, base_type_t has 2 template arguments; T1 and k1. The templates foo_t, bar_t, and baz_t derive from this base, using the derived template's parameter for T1, but providing a ...
3
votes
2
answers
97
views
Cannot detect protected base class method with SFINAE
I attempted the following approach using c++ SFINAE and std::declval to find if there exists the proper method in a base class, that can be called from the derived class. The derived class gets the ...
2
votes
1
answer
71
views
variadic-value-template-template with value-types given in parent template is accepted by clang but rejected by gcc
I'm building trait-types (similar to std::type_identity) to represent template-templates of the different flavors. Mixed-type variadic value templates are a special case, and I can only think of doing ...
1
vote
1
answer
118
views
std::conditional_t evaluate false result type when condition is true
I have currently this:
template<TagType TTag, IsTag ...Tags>
struct RequiredTagList
{
static constexpr const TagType index = TTag;
};
// -----------------------------------------------------...
2
votes
1
answer
122
views
declare return_void / return_value conditionally
I've tried std::enable_if and requires:
template <typename Ret>
struct promise_type {
auto get_return_object() {/*...*/}
auto initial_suspend() {/*...*/}
auto return_void()
-> std:...