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

0
votes
0answers
19 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 ...
2
votes
0answers
18 views

type_list with utilities

The post is follow up to my previous Typelist with extractor. The idea of the code is to provide type list with some handy features. Following is the list of features which are provided, in the order ...
4
votes
1answer
67 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 ...
2
votes
1answer
63 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 ...
0
votes
1answer
79 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
53 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
53 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
122 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
120 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
58 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
91 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
68 views

Object factory from interface types

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

MSD radix sort in C++

I have this MSD radix sort in C++: ...
1
vote
1answer
64 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
39 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
24 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
70 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
237 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 ...
3
votes
0answers
72 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
43 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
34 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
111 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
355 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 ...
3
votes
1answer
121 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 ...
9
votes
0answers
114 views

Permuting a typelist

Given a typelist, return a typelist of all the permutations of it. For example: ...
3
votes
1answer
79 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): ...
8
votes
1answer
165 views

Compile time integer square root for large numbers

This computes the integer square root at compile time for any \$0 \le N \le L\$ where \$L\$ is the largest integral representation of template parameter T. This ...
2
votes
1answer
181 views

Simple multi-dimensional Array class in C++11 - follow-up

Last week, I posted this question in order to get some comments and critiques on a simple implementation of a multidimensional array class -- hyper_array::array ...
4
votes
1answer
46 views

Invoking functions with arguments at a later time or multiple times

This is a class which stores a function pointer and arguments to that function, to call/invoke that function at a later point in time, or multiple times. Additionally, through polymorphism, it allows ...
6
votes
1answer
342 views

Simple multi-dimensional Array class in C++11

The new version of the code can be reviewed in Simple multi-dimensional Array class in C++11 - follow-up. The following code implements a simple multi-dimensional array class (...
4
votes
1answer
89 views

Implementing the basic elements of functional programming with C++ templates

With C++ templates, I've implemented a template list type with cons, reverse, merge, sort, filter, map, fold; and higher order template functions with currying. The C++ compiler can also work as an ...
3
votes
0answers
95 views

Invoke callable object passing arguments in “groups of N” using C++17 fold expressions

Interactive Wandbox example Inspired by this Stack Oveflow question, I've implemented a function that, when called with a desired arity, a callable object, and a variadic amount of arguments, calls ...
2
votes
1answer
82 views

A selection pattern for C++11

In simulating physical equations (such as fluid dynamics) it is common to write an application that deals with 1, 2, and 3 dimensions. A common C/Fortran approach is to make all vectors (for example) ...
4
votes
1answer
554 views

Optional base class template to get conditional data members

In generic code, I sometimes want to conditionally add a data member to a class template. Writing separate template specializations scales as 2^N for ...
8
votes
2answers
109 views

Template integer range, version 2

This question is a follow-up. The original question was itself a follow-up to an older question by @LokiAstari. The idea is to provide a compile-time integer range. This version incorporates ...
3
votes
1answer
287 views

Templated Singly-Linked List

I'm really new to C++ (very surprised at the leap from Python and others to C++!). The code compiles and works well. This took all day to get to work, and I've the tendency to move on after I get ...
5
votes
2answers
263 views

C++ vector that uses expression templates technique to increase performance of mathematical expressions

I've been reading Item 6 from Scott Meyers' Effective Modern C++ and noticed that he mentioned a technique called expression templates. I've decided to give it a try and implemented a vector that ...
10
votes
1answer
151 views

C++ SQL wrapper/Statement

Part 2: (Part 1) Working on my SQL project at last. The concept is easy to use and integrate SQL into C++. ...
14
votes
2answers
240 views

C++ SQL wrapper/Connection

Working on my SQL project at last. The concept is easy to use and integrate SQL into C++. ...
12
votes
1answer
191 views

Compile-time sieve of Eratosthenes

There are many instances of prime number sieve implementation both here and other places on the web, but I wanted something a little different. In particular, I wanted to create a static array of the ...
4
votes
1answer
226 views

Template Method Checker

I have written some template helpers to check if a class has a certain method with a certain signature. The code is based on this answer. I attempted to extend it for generic methods. An important ...
1
vote
1answer
206 views

C++ class template for notification management

Recently, I found myself frequently writing notification managing facilities. That is, one can register as a receiver by providing a callback, and another can send a notification to all registrants by ...
7
votes
2answers
394 views

Chebyshev polynomial evaluation class using C++1z fold expressions

I've been messing around with templates in C++14 and C++1z recently, and since I have somewhat of an obsession with optimization (and since my field of work relates to it) I decided to try to ...
10
votes
1answer
479 views

Compile-time printf-style format checking

Inspired by this open ticket on Boost, this seeks to complete the work there. Given a printf-style format string and associated arguments, a static_assert is ...
2
votes
2answers
513 views

Strongly-typed angle measures in radians and degrees

I often work with angles when writing code for 3D rendering and such. Personally, I prefer to measure angles in degrees, but many APIs (including the Standard Library) measure angles in radians. So ...
5
votes
1answer
343 views

Compile-time printf format checking

Compile time checking of printf-like format strings Inspired by this open ticket on boost, this seeks to complete the work there Given a printf-style format string and associated arguments, a ...
4
votes
1answer
175 views

Optimizing variadic template pack subsequence matching algorithm

I'm building a small MPL module in one of my utility libraries for fun and learning experience. One of the problems I'm trying to solve is getting a list of all indices where a sequence of types ...
2
votes
0answers
35 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 ...
1
vote
0answers
119 views

Template based return type from object and class method

I'm looking for a better implementation of this. The current solution looks bad to me and breaks the VC10 compiler if you call Create() with a method expecting two ...