Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.

Questions tagged [template-meta-programming]

For code that uses templates to generate compile-time executed code. For ordinary use of templates, use the 'template' tag instead.

Filter by
Sorted by
Tagged with
2 votes
0 answers
182 views

This is my second iteration of implementing try_lock_for/try_lock_until function templates in which I've cherry-picked a bunch ...
Ted Lyngmo's user avatar
4 votes
2 answers
124 views

I implemented a templated vector_view class that holds a reference to an std::vector and provides the following operations: ...
Raghav Malik's user avatar
6 votes
1 answer
236 views

I'm writing a library of IO functions for my physics laboratory class. In the meanwhile, I'm hoping to learn more about generic programming and C++20 concepts. Some context I usually came home from ...
GeometriaDifferenziale's user avatar
2 votes
1 answer
113 views

TL;DR https://godbolt.org/z/TMfb8z99h ...
Sergey Kolesnik's user avatar
2 votes
1 answer
117 views

Needed to do some Meta programming. I needed to check if a class has a specific member (one case a member variable second case a member type (two distinct use cases)). Since I am writing a library, I ...
Loki Astari's user avatar
  • 97.7k
4 votes
2 answers
503 views

I recently had to work on some conversion of literal strings and wondered if that could be done at compile time using template meta programming. I couldn't find many examples online, so I started ...
adepierre's user avatar
  • 135
7 votes
2 answers
256 views

Prior Notification This follows a previous review of mine that addressed the core helper function named make_skippable. The composition implementation presented ...
mahush's user avatar
  • 115
3 votes
2 answers
182 views

(Please note: the post about the compose implementation announced below is now available.) This is about decorating callables by making their argument and return value to be a ...
mahush's user avatar
  • 115
3 votes
1 answer
127 views

Below is a piece of template code which allows for adding a Tag to structure or class types. ...
Sam Coutteau's user avatar
3 votes
1 answer
191 views

I was mad C++ did not have support for printing containers. I also could not find a header only library for printing containers so I decided to make my own. My goals were: 1) practicing templates 2) ...
Doruk's user avatar
  • 423
3 votes
1 answer
172 views

I have a class template that stores an std::optional<T>. A very reduced version of the class template looks like this: ...
joergbrech's user avatar
2 votes
1 answer
267 views

I've tried to make a small template for the creation of distinct (incompatible) numerical types. For example both row and column indices are usually represented as the same underlying type. However it ...
Sam Coutteau's user avatar
4 votes
1 answer
1k views

I needed to find a way to convert a bunch of enums to string for displaying in C++. The two main ways I found when searching was using dark magic macros or voodoo magic template metaprogramming. As I ...
adepierre's user avatar
  • 135
4 votes
0 answers
68 views

Sometimes I find I want to call a function passing each of a set of types as a template parameter, but without needing to construct an object of those types. I also may want to do this in multiple ...
John Ilacqua's user avatar
4 votes
2 answers
253 views

I want to do template metaprogramming to compute the conversion from std::variant<Ts...> to ...
Tom Huntington's user avatar
3 votes
1 answer
121 views

Again, here is the previous question. I have (re)revised my custom scoped timer using the valuable feedback I got from a helpful member of this community. However I feel the need to ask this question ...
digito_evo's user avatar
-2 votes
2 answers
115 views

I'm trying to create some system for profiling and I need to track different data types (double, float int). I have a container that can hold some base type, and then perform actions on the concrete ...
kbz's user avatar
  • 99
4 votes
1 answer
2k views

I am writing some C++ code to interact with an external scripting language. I want to be able to register arbitrary C++ callable code as functions to be called from the script. The scripting library ...
David Woo's user avatar
  • 161
3 votes
1 answer
661 views

Intro I want to visit the value held by a class, which could be of multiple types. This class is very similar to a std::any, so I will be using this in this ...
mfacchinelli's user avatar
2 votes
1 answer
221 views

For mainly didactic reasons, I have designed my ElementsView<I, T> class template, which provides a view over the I th ...
joao's user avatar
  • 123
1 vote
2 answers
117 views

I am creating a template function with variardic arguments, to handle a specific classes that have some interface, method, member or whatever is specialized in a specialization area. However I came to ...
Ilian Zapryanov's user avatar
3 votes
1 answer
2k views

While solving an online excersise I have written some basic implementation for a visit function that works with std::any. The ...
Sergey Kolesnik's user avatar
2 votes
1 answer
771 views

I recently implemented a thread pool using std::functions. I only supported functions taking no arguments on the assumption that there would be no need to have them ...
jezza's user avatar
  • 205
3 votes
1 answer
3k views

I've been working on some kind of mapper that would allow me to map between types. My objectives: it should allow mapping between two enums it should allow mapping enum to string_view it should allow ...
bielu000's user avatar
  • 290
2 votes
1 answer
389 views

As a challenge/fun activity/task, I have implemented my version of std::is_constructible. Here is the source code: ...
Mansoor Ahmed Memon's user avatar
2 votes
1 answer
349 views

I have realized that all the digital filters of the IIR type have the same structure. They are described by difference equation in following form: $$ y(k) = b_0\cdot x(k) + b_1\cdot x(k-1) + \ldots +...
Steve's user avatar
  • 355
2 votes
0 answers
204 views

Goal: implement traits that for anything callable return its arity, return type and the argument types. Since pointers to data members are also callable, those should be handled (and be considered 0-...
Diederick C. Niehorster's user avatar
1 vote
1 answer
240 views

Update: there is a new version of this code: v5 is posted here Goal: implement traits that for anything callable return its arity, return type and the argument types. Since pointers to data members ...
Diederick C. Niehorster's user avatar
3 votes
0 answers
81 views

Update: there is a new version of this code: v4 is posted here Goal: implement traits that for anything callable return its arity, return type and the argument types. Since pointers to data members ...
Diederick C. Niehorster's user avatar
3 votes
1 answer
107 views

Update: there are new versions of this code: v3 is posted here and v4 is posted here Goal: implement traits that for anything callable return its arity, return type and the argument types. Since ...
Diederick C. Niehorster's user avatar
4 votes
1 answer
1k views

This is a follow up on c++20 compile time string utility, as suggested by G. Sliepen posted as a new question, so it can be reviewed on its own. The following code has suggested improvements from the ...
Dmitrii's user avatar
  • 95
5 votes
2 answers
4k views

While upgrading some meta-program running in production for years to the latest (c++20) standard, I rewrote this particular compile time string utility. Even though this new version produces desired ...
Dmitrii's user avatar
  • 95
1 vote
2 answers
957 views

I'm trying to reduce the boilerplate of a lot of header-only classes I'm using. Each of these classes must go through a registration step. I want this step to be defined in the same file as the class ...
Delgan's user avatar
  • 621
1 vote
1 answer
156 views

Annoyed at the tension between good software design principles that require well-defined delimitations between interface and implementations, and the requirements for critical code to run fast, which ...
lurscher's user avatar
  • 151
9 votes
3 answers
5k views

I'm reading "Modern C++ Design"(A. Alexandrescu, 2002) and practicing basic TMP in chapter 3. Typelists. Since the book is quite dated, I revised example codes in C++17-esque manner. Feel ...
frozenca's user avatar
  • 1,751
1 vote
1 answer
991 views

I don't know why there's no such function in std (at least I didn't find one). I need a conditional template function to return a reference to an object of T. ...
Sergey Kolesnik's user avatar
3 votes
1 answer
1k views

In our software we have some functions that return information through lvalue reference parameters, which, in some cases, are irrelevant for the calling code. For that reason, I tried to come up with ...
Matthias Grün's user avatar
1 vote
1 answer
443 views

Searching for a solution to my problem I've read many posts regarding templates in Qt (including those on SE) and didn't find a complete solution (or I should say a complete example of a solution) so ...
LRDPRDX's user avatar
  • 941
6 votes
1 answer
623 views

I'm implementing apply_each for tuple-like object as a general function which may be a combined version of for_each and ...
Desmond Gold's user avatar
2 votes
1 answer
319 views

I'm trying to replicate std::array but with modifications that I should put the private data member to the public so the class template ...
Desmond Gold's user avatar
2 votes
1 answer
136 views

I have this small C++ program for computing the \$n\$th Tribonacci number at compile-time. My main concern is: is it possible to get rid of the statickeyword (I had ...
coderodde's user avatar
  • 32.2k
1 vote
1 answer
1k views

I have recently come across a use case where I need to lump many maps into a single container. These maps can have different combinations of key/value types, but they all differ from one another. For ...
Emerald Weapon's user avatar
4 votes
3 answers
4k views

I wrote two template functions to serialize and deserialize structs representing messages to be sent and received via a TCP socket: ...
user avatar
2 votes
0 answers
330 views

Motivation I and the company is working on building C++ SDK automatically for several platforms, including Windows. In summary, I have to test somehow if the private member of function pointers' type ...
김선달's user avatar
  • 121
7 votes
3 answers
2k views

I'm quite new to the STL. Does this make sense? Is there a better way of removing the listeners instead of using shared_ptr while keeping the code short and simple? Is there something in the STL to ...
fededevi's user avatar
  • 330
3 votes
1 answer
253 views

I have been developing a control software in C++ and for implementation of the control algorithms I need basic matrix operations like addition, subtraction, multiplication and multiplication by scalar....
Student's user avatar
  • 395
2 votes
1 answer
1k views

Use-case in a nutshell: Interpolate fixed-sized data (a lookup table) that provides output values for combinations of a (fixed) number of inputs. The appropriate scaling is done externally, each axis ...
Stefan's user avatar
  • 813
5 votes
1 answer
714 views

About I'm writing a header-only template library for helping with binary IO. It is inspired by pack-d, which is in turn inspired by Python's struct module. I've only finished the output part and ...
Luka Aleksić's user avatar
4 votes
3 answers
480 views

In working on another problem, one component I needed was to calculate the centroid of a collection of complex objects. The well-known way to calculate this is to simply average the real and ...
Edward's user avatar
  • 67.2k
-1 votes
2 answers
4k views

I am writing color model logic in C++. I ask review in defining limits for the color model, by saying Limits I mean this. Consider a struct which represents ...
Hrant Nurijanyan's user avatar

1
2 3 4 5 6