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.
277 questions
2
votes
0
answers
175
views
Namespace-scope try_lock_for / try_lock_until pt. 2
This is my second iteration of implementing try_lock_for/try_lock_until function templates in which I've cherry-picked a bunch ...
4
votes
2
answers
121
views
Implementing views and slicing for arbitrarily nested `std::vector`s in a header-only library
I implemented a templated vector_view class that holds a reference to an std::vector and provides the following operations:
...
6
votes
1
answer
232
views
A generic function that reads a line of numeric values from a file
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 ...
2
votes
1
answer
90
views
Pattern matching with predicates support
TL;DR
https://godbolt.org/z/TMfb8z99h
...
2
votes
1
answer
115
views
Member detection within a class
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 ...
4
votes
2
answers
479
views
Compile time string manipulation in C++
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 ...
7
votes
2
answers
246
views
Function composition in the context of data processing pipelines
Prior Notification
This follows a previous review of mine that addressed the core helper function named make_skippable.
The composition implementation presented ...
3
votes
2
answers
176
views
Extending callable signature with std::optional in context of function composition (make_skippable)
(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 ...
3
votes
1
answer
121
views
(C++) Template code for adding tagging types to add additional context
Below is a piece of template code which allows for adding a Tag to structure or class types.
...
3
votes
1
answer
188
views
C++ printing library with templates
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) ...
3
votes
1
answer
170
views
Partial specialization of class template with minimal code duplication
I have a class template that stores an std::optional<T>. A very reduced version of the class template looks like this:
...
2
votes
1
answer
264
views
Template for making distinct numeric type aliases
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 ...
4
votes
1
answer
1k
views
C++ enum to string conversion utility
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 ...
4
votes
0
answers
62
views
Variadic pack class providing operations over types without constructing objects of those types
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 ...
4
votes
2
answers
245
views
Transpose types variadicly
I want to do template metaprogramming to compute the conversion from std::variant<Ts...> to ...