Template meta-programming is a meta-programming technique in which templates are used by a compiler to generate temporary source code, which is merged by the compiler with the rest of the source code and then compiled.

learn more… | top users | synonyms

2
votes
0answers
15 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 ...
1
vote
0answers
19 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 ...
3
votes
0answers
33 views

for_each over multiple containers

I have worked up an implementation of a for_each style function that can iterate over multiple containers at the same time. ...
3
votes
0answers
41 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 ...
8
votes
1answer
141 views

A modern and extensible C++14 logger

I recently wrote this C++ Logger API code for a game engine. It needs to be as fast as possible so I tried to postpone everything to compile-time using different template meta-programming tricks (for ...
2
votes
2answers
109 views

A generic logger in modern C++

I've created a simple logging system that I'm planning to use and I've tried out some modern C++ features to make it generic. First I've made a log class that represents a single log message: ...
4
votes
0answers
42 views

Converting a get-by-index function into an iterator for use with STL algorithms

This is a solution to Advent of Code 2016, Day 8. The tricky part of this problem is that you have to be able to rotate both the rows and columns of a two-dimensional array. Rotating a row is easy ...
3
votes
1answer
85 views

Generic Template Markov Chain

This is a simple real state based markov chain (I'm using real states instead of a markov matrix to enable making an animated version later). My goal was to make the markov chain as generic and ...
4
votes
0answers
54 views

2D grid container with arbitrary multiple data types

I've been toying with the idea of making a simple game. In game development, it is good to do things in a more struct-of-arrays style rather than arrays-of-structs style, due to cache locality. ...
3
votes
1answer
137 views

Generic matrix type in C++

This snippet is about a generic matrix type. The nice part is that given two matrices with respective entry types, say, of short and ...
1
vote
1answer
68 views

Binary search for random access iterators in C++

I wrote a generic binary search routine in C++ for ranges that are specified by random access iterators. In case the user inputs a range with non-random access iterators, an exception will be thrown. ...
1
vote
0answers
29 views

Templated string to enum mapping code

I'm trying to create series of template classes that I can use to simplify the process of adding string to enum mapping support. The goal is to minimize the amount of code I have to repeat to define ...
3
votes
1answer
82 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: ...
5
votes
1answer
131 views

Concatenate two containers, e.g. vector or strings

I'd like to create a function that can concatenate vectors or strings. It must Keep correct order Be optimal This is the solution I came up with: ...
2
votes
0answers
74 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 ...
3
votes
1answer
298 views

Hashing a tuple in C++17

C++ doesn't supply a std::hash<std::tuple<...>>, so I decided to implement one. However, I was viewing this as more of a hash library than extensions to ...
1
vote
0answers
43 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 ...
2
votes
1answer
49 views

Template function which determines how to move-assign a type

In some code that I am writing, I am manipulating some heterogeneous containers of user-defined types. I desperately need to be able to move-assign these types without generating exceptions. However,...
3
votes
0answers
189 views

constexpr Sin Function C++ 14

I have written a constexpr sin function using c++14 and would like to know what I can do to improve it. I am trying to balance code clarity/maintainability with ...
5
votes
0answers
94 views

Making template meta-programming a little easier with integer packs

In template meta-programming, integer sequences and ranges are very useful. I've made a couple of utility classes that do various operations on compile-time integer packs. The implementation is non-...
2
votes
1answer
79 views

Simple Contains() Function

I wrote simple generic function to check if any STL container has an element. It seems work fine. I have tested it with VC++, GCC and Clang compilers. It works perfectly. How can I improve it further....
2
votes
0answers
40 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 ...
4
votes
0answers
171 views

Selection sorting a type list (compile-time)

This question has the tuple_selection_sort<> template that sorts the variadic template of a tuple using a comparator (any template taking two types that has a ...
2
votes
1answer
51 views

C++ Socket Part-2 A (Utilities)

This is the code I use to dynamically build error messages. Utility.h ...
0
votes
3answers
106 views

Extend number of arguments in std::hypot

I would like to call std::hypot with many arguments (not just 2 or 3). Mandatory requirements: fast run at compile time when possible Non-mandatory requirement: ...
6
votes
0answers
140 views

type_list with utilities

The post is follow up to my previous Typelist with extractor. The type_list and extraction feature code is identical to the accepted answer (from user2296177). The ...
4
votes
1answer
124 views

Typelist with extractor

The purpose of the code is to store arbitrary number of types. The type can be extracted from it using Extract template, which uses template recursion to get the needed type. There will be compilation ...
3
votes
1answer
183 views

Dynamic multidimensional arrays

My application needs Field objects, which encapsulate 1D, 2D or 3D gridded data. The number of dimensions and their size are known only at run time. Furthermore, I ...
1
vote
1answer
165 views

C++ simple event system

I posted an earlier version of this code a couple of days ago, so it's the updated version of the code posted here. ...
4
votes
0answers
128 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 ...
2
votes
0answers
122 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 ...
6
votes
1answer
138 views

Generic and accurate floating point “equality”

Like those who have come before me, I foolishly have sought to implement a generic, efficient, idiomatic, and most importantly correct method of comparing floating point numbers for equality. Like ...
1
vote
1answer
238 views

Dependency injection class in C++

In a recent project I started passing dependencies to classes as constructor arguments, instead of using local instances. This makes unit testing straightforward (with mock objects), but manual ...
3
votes
1answer
61 views

Type safe variadic cout implementation

I use console a lot, so I thought this may help me. It's supposed to be simple, safe, and fast. Any ideas? http://ideone.com/INXub0 ...
3
votes
1answer
934 views

C++ template Partial Specialization Member Function; Am I doing right?

I'm trying to improve my C++ template metaprogramming skills. From my understanding, I can't partially specialize a function(either member function or not). So, I need to define another class that can ...
5
votes
1answer
83 views

Object factory from interface types

I have a library that defines a bunch of ISprite interfaces, like IPieceSprite and ...
1
vote
1answer
314 views

MSD radix sort in C++

I have this MSD radix sort in C++: ...
1
vote
1answer
82 views

Template for wrapping fundamental types and other basic POD structs in C++

I wrote this, which I'm not sure if it's of any use yet but at least it saves me some time when writing atomics to a file or raw memory. What I was thinking is that the conditional in the ...
3
votes
0answers
44 views

Multi-dimensional view of a one-dimensional object

Sometimes, we create a one-dimensional object, but want to access it in a multi-dimensional way. For example, you can access an int[8] array object in a 2x2x2 way. ...
1
vote
0answers
26 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 ...
3
votes
1answer
75 views

Handy tool that provides easy syntax for specifying multi-dimensional types in C++

The syntax for specifying multi-dimensional types in C++ is messy. For example, to specify a two-dimensional std::vector<int>, one has to write ...
4
votes
2answers
826 views

Filtering variadic template arguments

I wrote some code to implement a way to filter the arguments of a variadic template based on their type. My current solution requires many helper meta-functions and I'm sure that there must be a ...
4
votes
0answers
108 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 ...
5
votes
0answers
44 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 ...
7
votes
1answer
44 views

Utility class for robust EBO

In modern C++, many classes accept a policy type as a template parameter. The author of the class does not know in advance what kind of policy its class will be ...
15
votes
2answers
121 views

Fixed array with configurable bounds

A interesting challenge was brought to my attention: to "flip" an array. I thought it might be more convenient if its bounds were symmetrical, say [-N..N] instead ...
6
votes
4answers
1k views

Hash table and linked list implementation in C++

I'm trying to improve my understanding of inheritance and template classes in C++ so I coded a hash table (see compilable source code below). I would be greatly appreciative of any comments on how to ...
4
votes
1answer
327 views

A non-recursive tuple_element<index, Tuple> implementation

This is basically a non-recursive std::tuple_element implementation. Note To make this non-recursive, you must replace ...
12
votes
1answer
201 views

Permuting a typelist

Given a typelist, return a typelist of all the permutations of it. For example: ...
3
votes
1answer
133 views

Egg drop problem solution in template meta-programming [closed]

I have implemented a dynamic programming solution of the egg-dropping problem (this problem, but generalized for any number of eggs and floors): ...