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.
8
votes
2answers
103 views
Functional composition of member function predicates
In C++11, it is en vogue to use small lambda expressions to produce ad-hoc predicates. However, sometimes it's fun to create predicates in a functional, "point-free" way. That way, no function bodies ...
1
vote
0answers
66 views
CRTP overload-set nightmare [closed]
I'm not sure if this belongs on CodeReview or StackOverflow, but we'll start with it here.
Here is an anonymized and simplified version of some code I have that uses the Curiously Recurring Template ...
3
votes
2answers
91 views
lockbox (a boost-like container)
So I introduced myself to templates in C++11 and I have to say it's really confusing, but also very fascinating. I just need to get my head around what happens at compile time so that I don't wind up ...
1
vote
0answers
107 views
Template parameter pack of parameter packs [closed]
Two things about C++11 variadic template syntax bother me because they make basic concepts hard to code and read.
The choice of list operations allowed on parameter packs is arbitrary.
The ellipsis ...
3
votes
1answer
69 views
Should I use an object or type as trait?
Edit: Disclaimer: I am new to templates and traits.
I apologize in advance if this is a bad question.
I am refactoring two similar classes with small differences strewn all over them into one ...
4
votes
1answer
684 views
C++ compile-time checked switch 'statement'
In the project I work on there are several places where a switch statement is used on a type enum. (I know, better to use virtual functions or a visitor pattern or something, but sometimes switching ...
3
votes
1answer
254 views
Could this deferred execution scheme be any simpler?
I've created this scheme to preserve function calls until all the arguments are available. The stub_op classes will be replaced with classes that implement a forward-like mechanism that receives ...
5
votes
1answer
126 views
Type to instance map
I needed a class where I could store an instance of any type. The goal was an interface as follows:
class TypeMap {
template<typename T>
T& get();
};
Such that:
Iff &m1 == ...
1
vote
1answer
430 views
Review of C++ singleton
Originally posted on Stack Overflow.
So far, I've used this in a few places and it seems solid.
This is what I usually do to make a singleton:
// Assume x86 for now
#ifdef _MSC_VER
#include ...
2
votes
0answers
941 views
JSON Serializer
Carrying on from:
Yet another C++ Json Parser
Yet another C++ Json Parser (Recursive)
All the code is available from git hub: ThorsSerializer but only reviewing a small section here.
The idea is ...
2
votes
1answer
212 views
How can I improve the design of this serialization mechanism?
I'm working on caching library which is intended to work with all types of values.
Values are represented as instances of value_type: value_type holds a std::vector<char> for the raw data, and ...
3
votes
0answers
166 views
Variadic function with restricted types
I am designing a class which (among other things) acts as a vertex in an undirected graph.
#include <iterator>
#include <string>
class Node
{
public:
explicit Node(const ...
9
votes
1answer
315 views
D2.0 mixin and template-heavy code - Building a silverlight clone
Update : The code is on github for anyone interested. I know it's not very useful but I'm having fun with it. link
I've made a mock version of silverlight in D2. It is meant to output html but ...
5
votes
1answer
444 views
Meta-program to find square numbers
I'm new to template meta-programming and wrote some code to determine if a number is a perfect square. For example, in my program, SQUARE<1>::value and SQUARE<4>::value evaluate to true ...