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

4
votes
0answers
29 views

ThorsSQL Lib Utility

These are some utility functions that I use for building error messages: SQLUtil.h ...
5
votes
0answers
82 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: ...
3
votes
1answer
67 views

c++ std::array implementation

Just after a review of my implementation of std::array. I created this to find the sweet spot between speed and nice code. I would really appreciate any guidance towards improving. Note: I use parts ...
4
votes
1answer
47 views

`std::move_as_tuple` and `std::when_all`

Working with futures and .then, I keep running into the problem of needing to "capture by move" in a lambda. In fact, not only that, but when implementing e.g. <...
3
votes
0answers
60 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 ...
2
votes
0answers
27 views

C++ generic double-dispatcher/visitor

I'm trying to reduce the boilerplate code for the visitor/double dispatcher pattern. First I've created a way to enforce the dispatcher to declare the dispatch(T) function for every type supported and ...
1
vote
1answer
62 views

Insane template metaprogramming madness

Given any callable, deduces the first parameter in the parameter list of the function. Be ware, not for light hearted. ...
16
votes
1answer
452 views

Execute a function n times, where n is known at compile time

Motivation In this question, a user asked whether it is possible to inline the following function: ...
1
vote
1answer
72 views

Simple quadtree template implementation

I'm returning to C++ after more than 10 years. The code I wrote for a simple quadtree style class has a ton of new elements I haven't used. I'm looking for comments on the design and not necessarily ...
3
votes
0answers
51 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
38 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
37 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
49 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
175 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
164 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
47 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
98 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
64 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
166 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
89 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
33 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
0answers
125 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
147 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
112 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
406 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
50 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
54 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
269 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
97 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
80 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
42 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
201 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
58 views

C++ Socket Part-2 A (Utilities)

This is the code I use to dynamically build error messages. Utility.h ...
0
votes
3answers
122 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: ...
9
votes
0answers
169 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
166 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
219 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
239 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
159 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
141 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
141 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
289 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
64 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
1k 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
89 views

Object factory from interface types

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

MSD radix sort in C++

I have this MSD radix sort in C++: ...
1
vote
1answer
89 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
77 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 ...