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.
3
votes
1answer
67 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
56 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
22 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
45 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:
...
4
votes
1answer
109 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
56 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 ...
2
votes
1answer
146 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
25 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
47 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
98 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
83 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
74 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
38 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
109 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
46 views
C++ Socket Part-2 A (Utilities)
This is the code I use to dynamically build error messages.
Utility.h
...
0
votes
3answers
90 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
133 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
105 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
131 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
109 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
86 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
88 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
131 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
181 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
456 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
81 views
Object factory from interface types
I have a library that defines a bunch of ISprite interfaces, like IPieceSprite and ...
1
vote
1answer
154 views
1
vote
1answer
76 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
42 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
25 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
73 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
581 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
94 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
41 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
116 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
685 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
251 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
167 views
Permuting a typelist
Given a typelist, return a typelist of all the permutations of it. For example:
...
3
votes
1answer
98 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):
...
10
votes
1answer
195 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
256 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
50 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
645 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
95 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
111 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
92 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) ...
7
votes
1answer
102 views
4
votes
1answer
898 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 ...