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
1answer
69 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....
1
vote
0answers
33 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 ...
3
votes
0answers
71 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
36 views

C++ Socket Part-2 A (Utilities)

This is the code I use to dynamically build error messages. Utility.h ...
0
votes
3answers
82 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
112 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
80 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
81 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
87 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
58 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
60 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
124 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
127 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
125 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
110 views

MSD radix sort in C++

I have this MSD radix sort in C++: ...
1
vote
1answer
68 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
40 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
303 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
36 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
405 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
144 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 ...
10
votes
1answer
124 views

Permuting a typelist

Given a typelist, return a typelist of all the permutations of it. For example: ...
3
votes
1answer
80 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
171 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
202 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
49 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
408 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
96 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
665 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
136 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
323 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
311 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
166 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
245 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
207 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
245 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
222 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
419 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
510 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 ...
3
votes
2answers
555 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 ...