Skip to main content

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.

34 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
8 votes
0 answers
567 views

Simple, intuitive and (hopefully) safe EventDispatcher

For my own game engine I need an event system. I tried to avoid the single-huge-enum-approach for minimizing compile times. The BasicEventListener is the (...
Tim Diekmann's user avatar
6 votes
0 answers
509 views

Console Command module (in-game console or base for script engine)

I've created a console/terminal command handling module that allows the programmer to bind functions to a command name and later execute them from std::string. What's new is that it handles most stuff ...
RippeR's user avatar
  • 161
5 votes
0 answers
1k views

Tuple-like container for packed data

I'm writing some code which needs to be compatible accross a Cortex-M based embedded device and x86 / x86_64 based PCs. I needed a solution for sending binary data between the Cortex-M and the ...
Venemo's user avatar
  • 243
5 votes
0 answers
2k views

Generic sliding window

The code implements fully generic sliding window with linear complexity. It should usually be paired with transforming iterator to reach full potential. Sliding window is a grouping of elements by ...
Incomputable's user avatar
  • 9,534
5 votes
0 answers
69 views

Using the llvm::iterator_adaptor_base

I'm currently working with the LLVM JIT framework. There is some graph I had to implement for internal cost bench-marking. It has cyclic node dependencies, so I have to use ...
Minor Threat's user avatar
5 votes
0 answers
1k views

C++ class "overload" using variadic templates and wrapped function pointers

I'm using C++11 and I have the following problem (pseudo C++): ...
jchnkl's user avatar
  • 51
4 votes
0 answers
53 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 ...
John Ilacqua's user avatar
4 votes
0 answers
1k views

A wrapper for (perfect forwarding + initialization)

Problem Perfect forwarding is known to be imperfect when it comes to list-initialization; I'll use std::construct_at as an example: ...
L. F.'s user avatar
  • 9,580
4 votes
0 answers
49 views

Modular graph searcher

some words in forehand: Unfortunately this post is very long, thus I decided to put the whole and compilable code into an online compiler. The link is at the end of this post. In the last few days I ...
DNKpp's user avatar
  • 771
4 votes
0 answers
139 views

Accept constructor arguments from a given subset of types

I found myself often in the position that I want to have multiple arguments in a constructor which could be in any order. For example: ...
Maikel's user avatar
  • 740
4 votes
0 answers
862 views

Custom basic std::variant

I was amazed by std::variant and got inspired to write my own. For now, it supports constructor+destructor pair, assignment operator and ...
Incomputable's user avatar
  • 9,534
3 votes
0 answers
57 views

invocable_traits v3

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
0 answers
66 views

Getting around gsl/span's restriction on temporaries

The goal of this code is to allow temporary RHS variables to be used in a span, specifically as an argument to a function, to be deleted later after the function completes, allowing the passing of ...
Krupip's user avatar
  • 641
3 votes
0 answers
64 views

Tagged Tuple with "special" copying

This is my first serious post on any stackexchange so any criticism is welcome. Github link to the code in this question: https://github.com/yevsev/tagged_tuple Problem statement For a computation ...
robert's user avatar
  • 31
3 votes
0 answers
210 views

Templatized GLib asynchronous queue

I'm working on a legacy C++ project, which is using GLib for its Main Event Loop. This has caused a lot of ugliness because it mixes C++ and C paradigms (no C++ wrapper for GLib had been used). ...
Wizard79's user avatar
  • 141
3 votes
0 answers
162 views

Trait class for a serialization framework

In a current project I have implemented a small non-intrusive serialization framework based on type traits. The generic trait template looks like this: ...
Kamajii's user avatar
  • 147
3 votes
0 answers
512 views

Replacing dynamic polymorhism with static polymorphism in C++

Motivated due to the fact, that the avr-g++ places the vtables in RAM, I wrote a replacement using static polymorphy. Consider the following example: ...
wimalopaan's user avatar
3 votes
0 answers
304 views

A way to automatically reorder struct fields by their sizes in descending order

Using constexpr and preprocessor magic it is possible to cook a struct which have a minimal size between all possible sizes, keeping all the data members properly ...
Tomilov Anatoliy's user avatar
3 votes
0 answers
974 views

zlib wrapper class

I needed to write zlib wrapper class for my application, so I can change it with different algorithm later if I want to do so. Here is the simple version: ...
Nick's user avatar
  • 1,572
3 votes
0 answers
274 views

Any class implementation

I was inspired from question here, to implement function container that holder any kind of function by using boost::any, I have carried on and extend it further to make the functions holder accept ...
MORTAL's user avatar
  • 3,278
3 votes
0 answers
863 views

C++ Event Emitter

I needed an event bus in C++ with a few features: Possibility to add/remove both functions and member methods. Ability to remove automatically those listeners that wrap member methods of expired ...
skypjack's user avatar
  • 131
3 votes
0 answers
117 views

Counting words in files - follow-up 2

Previous question: Counting words in files - follow-up I have fixed punctuation problems in my previous code by using template, because it is easy to understand and my focus on template mechanism. ...
MORTAL's user avatar
  • 3,278
2 votes
0 answers
172 views

invocable_traits v5

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
2 votes
0 answers
251 views

Generic way to access private/protected members

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
2 votes
0 answers
60 views

Using Boost's Runge-Kutta integration capability in a templated mathematical model

This is my first time using Boost and templates in general, so I'm mostly looking for a style critique on my C++. In particular, I'd like feedback on: state_type, ...
ijustlovemath's user avatar
2 votes
0 answers
84 views

Compile time logical operations for web framework in C++

I'm working on a web framework in C++ and there's this part that I need to do something like this: ...
The Moisrex's user avatar
2 votes
0 answers
65 views

Creating an array of distinct objects with an identical method that can be evaluated (mapped) at compile-time (constexpr)

In a ray tracing project that I'm trying to make compile-time (constexpr) for fun and challenge, I've run into a bit of an issue: I have an object (intersection) that needs to refer to one of a group ...
Sebastian's user avatar
  • 143
2 votes
0 answers
58 views

SI type safe unit calculations (revised)

This is the continuation of the questions raised in this thread I did include the improvements that were mentioned but still feel like, I do more copies than I need to. Also I am unsure about the ...
CD86's user avatar
  • 173
2 votes
0 answers
609 views

Registering data types with logger at compile time

I am working on a data recorder in my library for pseudo-realtime systems. I have a default templated record() function to cover basic data types, and library users ...
ryan0270's user avatar
  • 121
2 votes
0 answers
106 views

Bigger coroutine class

This is my attempt to implement the style of coroutines I described in my answer to Small coroutine class. What do you think of it? (My unusual dialect is due to my compiling with ...
Quuxplusone's user avatar
  • 19.4k
2 votes
0 answers
248 views

Library for manipulation of binary protocol headers

I'm starting with implementing a TCP/IP stack for embedded systems which will be done in C++ and I've found I need a good way to work with protocol headers involved (e.g. ARP, IP, TCP). Major ...
Ambroz Bizjak's user avatar
2 votes
0 answers
56 views

Using lists of types to specify types conversion order for operations

I want a mechanism for specifying arbitrary order of type conversion for arbitrary set of types for each operation on that types (separately). For example, let's have set of types ...
Alexander Morozov's user avatar
2 votes
0 answers
44 views

Type traits for ConfigLoaders

I recently added this ConfigLoader class to my project : it loads information (in this example for a window) from an XML config file, using boost. I would like to ask your advice if this is a good ...
MattMatt's user avatar
  • 593
2 votes
0 answers
106 views

Storage policies

I often come across situations where a library component needs to buffer a large amount of data for later processing. The problem is that at the design stage a choice needs to be made as to whether to ...
Daniel's user avatar
  • 825