Skip to main content
Filter by
Sorted by
Tagged with
0 votes
1 answer
199 views

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 ...
Hazret Hasanov's user avatar
0 votes
1 answer
137 views

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(...
Hazret Hasanov's user avatar
0 votes
2 answers
228 views

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 ...
StillUsesFORTRAN's user avatar
1 vote
1 answer
143 views

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 ...
Sneed Deens's user avatar
2 votes
2 answers
136 views

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() (...
Sergey Kolesnik's user avatar
4 votes
0 answers
254 views

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 ...
Simon Struthers's user avatar
0 votes
1 answer
89 views

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; ...
Gusen14ka's user avatar
3 votes
0 answers
167 views

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 ...
xmllmx's user avatar
  • 44.6k
3 votes
2 answers
250 views

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 ...
name's user avatar
  • 333
5 votes
1 answer
210 views

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. ...
Desmond Gold's user avatar
  • 2,278
9 votes
3 answers
955 views

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 ...
jordi's user avatar
  • 195
3 votes
2 answers
99 views

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 ...
Gemini Em's user avatar
2 votes
1 answer
75 views

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 ...
xaxazak's user avatar
  • 998
1 vote
1 answer
129 views

I have currently this: template<TagType TTag, IsTag ...Tags> struct RequiredTagList { static constexpr const TagType index = TTag; }; // -----------------------------------------------------...
DipStax's user avatar
  • 572
2 votes
1 answer
125 views

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:...
shynur's user avatar
  • 505
7 votes
0 answers
121 views

I've been clarifying some of my understanding of C++ meta-programming. So looking at a function like (my code) using namespace std; template<class... As, class F> constexpr auto for_each(tuple&...
Eric Auld's user avatar
  • 1,246
2 votes
1 answer
109 views

Let's say I have I have some container template type Container that accepts object types, and some std::function-like template FunctionWrapper that accepts function types. Further, I have a struct S ...
jacobsa's user avatar
  • 7,875
4 votes
3 answers
170 views

I need sometimes to filter some types from a given parameter pack and get the result as a std::tuple. For instance, it can be a filter based on the index of the types in the pack. As an example, here ...
abcdefg's user avatar
  • 4,637
1 vote
1 answer
81 views

I am trying to setup a system where I or a user can implement a specialization to a templated function and have it be put into a static collection of function pointers defined in another file, or even ...
FernGame's user avatar
2 votes
0 answers
67 views

I know that the following code(down bellow or on godbolt) won't be possible as is, because the nested-name-specifier creates a non-deduced context. But I have hopes that with a user-defined deduction ...
hr0m's user avatar
  • 2,875
4 votes
1 answer
135 views

My goal is simple: I want to specialize a method template for multiple types at once. I've googled around for possible ways to accomplish this task and found that concepts can be used for that. I've ...
Ruslan's user avatar
  • 87
1 vote
1 answer
106 views

I'm writing a policy class, TrivialSerializer, that'll slot into a function later in C++. This policy needs to serialize objects whose types may be specified to certain extent by other policies, and ...
AdamantConlanger's user avatar
4 votes
1 answer
103 views

I found a strange behavior with a custom type trait I was writing and further found that different compilers are having different behavior with the trait. The goal is simple, I want to detect if a ...
I Less3 CPP's user avatar
1 vote
0 answers
109 views

I have been working on a pet project on C++ where I am trying to parse a json at compile-time (json is stored in a fixed size string, so it's known at compile time). Given that this is not the easiest ...
uxsu's user avatar
  • 11
0 votes
2 answers
135 views

I frequently encounter a kind of problem illustrated in the following minimal hypothetical example. I have a library function like this: /** * `shoes` can take values {0, 1, 2} * `isNew` can take ...
user2961927's user avatar
  • 1,790
1 vote
2 answers
94 views

I want to call different template member functions with the same sequence of input types, in order to reduce boilerplate code, I tried to implement a dispatcher function, for_each_type, struct A { ...
user416983's user avatar
  • 1,106
-2 votes
1 answer
83 views

I am trying to wrap a call of WinAPI function in the function that will automatically check for an error: template<typename T = void,typename function, typename ...Args> T winapi_wrapper(...
sat0sh1c's user avatar
2 votes
0 answers
99 views

I made a class Point which can be 1D or 2D. First, here is the code (it is compilable in C++17 on any online compiler): #include <iostream> #include <type_traits> enum class Axis : ...
Oodini's user avatar
  • 1,463
2 votes
3 answers
200 views

How do I access a static constexpr inline variable from a CRTP-type class? It beats me as to why T::X is not available in struct Templated? template <typename T> struct Templated { static ...
r webby's user avatar
  • 512
0 votes
1 answer
67 views

For a project I'm working on I have been trying to implement a typelist with template class.s as the possible types. The relevant parts of my implementation are below. It works well generally but it ...
Gemini Em's user avatar
2 votes
1 answer
69 views

Consider the following types. template<int data_> struct CompileTimeData{ static constexpr int data = data_; }; template<int data> struct S{}; In C++17, how does one convert a tuple of ...
Abator Abetor's user avatar
0 votes
2 answers
200 views

Most knows that template meta programming is in general faster than virtual dispatch in C++ due to types of templates were decided in compile time while virtual functions required runtime lookup on ...
bedman3's user avatar
0 votes
0 answers
82 views

This task arised while implementing a system for counting memory used by objects. I have calcClassSize function that accepts an object of type S and a parameter pack of all S fields. The parameter ...
Alex Jenter's user avatar
  • 4,452
2 votes
2 answers
278 views

I have a std::variant of possibly repeated types, and I would like to increment the active index of the variant. Here is an example demonstrating what I would like to do: template <typename... Ts&...
Bernard's user avatar
  • 5,800
3 votes
1 answer
123 views

I have measured a significant speedup in my application if my function foo accepts primitive types by value instead of by universal (forwarding) reference. The speedup is lost however, if non-...
lobelk's user avatar
  • 531
2 votes
1 answer
118 views

Consider the following C++23 code: #include <tuple> #include <cstdio> #include <iostream> struct W1 { int n; bool b; W1(int x, bool f) : n(x), b(f) {} }; struct W2 { ...
lobelk's user avatar
  • 531
0 votes
1 answer
81 views

I want all calls to functions from a certain library to be wrapped with a call to my function. For example, whenever a function from the library <glad/glad.h> is called, my function log() is ...
user28091278's user avatar
4 votes
2 answers
208 views

Is there a way to figure out whether the current scope is a global function/static class-method or a class-method? I thought of the existence of this, but I'm unable to find a technique which doesn't ...
Patrick B.'s user avatar
  • 12.6k
3 votes
2 answers
98 views

The C++ standard library provides std::char_traits<T> to unify the handling of character data without regard to the specific character type used. It also provides <type_traits> for more ...
Adrian McCarthy's user avatar
1 vote
0 answers
47 views

I want to check if a (long) list of types (in this example just char and int) fulfil a (long) list of C++20 concepts (in this example just is_foo and is_bar). I currently approach this is as follows: #...
akerstjens's user avatar
4 votes
4 answers
260 views

I have started using this type of construction, which depends on C++20's explicit template parameters for lambdas: template<typename... Ts> struct Foo { std::tuple<Ts...> bars; auto ...
kc9jud's user avatar
  • 402
1 vote
1 answer
90 views

The question is simple (but not so the solution I guess...). I want to apply a function to index 0 of n tuples with args, later to index 1 of tuple the same tuples with args... and so on. Given this: ...
Germán Diago's user avatar
14 votes
1 answer
817 views

This post talks about a method that counts the number of members in class: struct UniversalType { template<typename T> operator T(); }; template<typename T, typename... A0> consteval ...
abcdefg's user avatar
  • 4,637
1 vote
2 answers
167 views

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
  • 531
2 votes
1 answer
87 views

I tried to compile old code (~15 years old - luabind) that uses very old boost version (sth like 1.30) with new version of boost 1.86. I replaced some apply_if usages with eval_if like it is suggested ...
BartekPL's user avatar
  • 2,460
0 votes
3 answers
199 views

From several integral constants, it is possible to define a trait Sum that returns the sum of all constants. For instance, we can define the following: #include <type_traits> template<...
abcdefg's user avatar
  • 4,637
1 vote
3 answers
98 views

I want to write a table class which takes as argument multiple columns to create the table. This is my attempt to do so. template <typename T = double> class table { private: using type = ...
Arnab Mahanti's user avatar
1 vote
1 answer
70 views

Is it possible to define a function which provides inspection of its templated argument with a specialization for std::variant, without actually including <variant>? Of course for the ...
Donald Ninetyfive's user avatar
2 votes
1 answer
76 views

I want to construct an object of a type which is selected at runtime based on an enum class value. The classes A and B have multiple constructors with various numbers of arguments which may be used at ...
Arnab Mahanti's user avatar
0 votes
1 answer
74 views

What I want to achieve The motivation is I want to have template with form template<typename T, typename ...Args> where T is some class type. And I want a specialised version of this template ...
BookSword's user avatar
  • 340

1
2 3 4 5
49