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

6
votes
2answers
139 views

Policy-based, variadic logger class in C++

I've been exploring design based around some of the more advanced C++11 features lately, and some of them are turning out to be rather useful for some projects I'm working on. One is this ...
2
votes
1answer
98 views

Variadic template data pack strucuture designed for debug/trace log (variable-sized records)

I am currently writing this pack template to pack all the values (raw / fundamental + arrays of such, especially c-strings and ...
5
votes
2answers
63 views

writeln() and format() with variadic templates

I wanted to get better acquainted with variadic templates, so I decide to try to implement a function like D's writeln(), just for fun. ...
2
votes
1answer
53 views

C++ messaging using templates

I wanted to allow components of my program to communicate without the components knowing about each other, thus keeping coupling low. So I devised some template classes that implement the observer ...
4
votes
2answers
70 views

Value Iteration Implementation for MDPs

I've been working for a while on a decision theory library, and since I've never really had any formal training in code best practices I'd love to hear your feedback. This particular class is one of ...
3
votes
0answers
67 views

CRTP object counter to track accidental singleton instantiation

I have used CRTP to implement an object counter for singleton classes. This way I can keep track of accidental attempts to instantiate more than one object. It is a header only class: ...
10
votes
1answer
140 views

Template integer range

This is a follow-up of an old question by @LokiAstari, modified for the current community challenge. The idea is to provide a compile-time integer range. I applied all the modifications that I ...
4
votes
2answers
104 views

Function object passing for a task scheduler

Here is my full implementation of a generic Functor-like class: ...
5
votes
2answers
95 views

Providing const- and non-const overloads of a strstr() implementation

In a question about reimplementing strstr(), I posted an answer. I pointed out a need for const- and non-const versions of the function, and provided ...
7
votes
2answers
261 views

std::tuple foreach implementation

I wrote a "foreach" implementation for std::tuple: ...
2
votes
1answer
101 views

std::tuple objects or rvalue references?

I have some small "plugin system" (not sure this is right name). It allow you to store objects (plugins), and then call some methods from each of them. With this approach we have absolutely no ...
5
votes
1answer
95 views

Test whether a type T is among the types of a tuple

In SO I asked for a way to do it without variadics. I also provided a typical "normal" implementation with variadics : ...
5
votes
1answer
85 views

Template function specialization with code duplication

I'm working on a libcurl binding for NodeJS, and to get info from a curl handler, using curl_easy_getinfo, I've created a template function, the issue, is that the ...
5
votes
1answer
150 views

User defined literal for std::integral_constant

I created a user defined literal _c to convert an "integer" literal into an std::integral_constant. Basically, the goal is to ...
1
vote
0answers
63 views

Template container simulating SQL “select” and “where”

I want to simulate, in C+, the fact that in a form with drop down (or combo boxes), you can filter by selecting items and then projecting on a given set of properties for these item. In a SQL-like ...
1
vote
1answer
149 views

Basic templating engine in F# using F# syntax

I've been working on a rough idea for a templating engine (mostly as a learning project) using the F# syntax. How "correct" is my code in terms of being idiomatic F#? Are there F# features which would ...
10
votes
2answers
880 views

Compile time decorator pattern in C++ with templates

I'm doing some high energy physics modelling in C++. I have written code that implements class that score interactions of particles with detector material. Here is a base class: ...
6
votes
1answer
83 views

Dynamically call lambda based on stream input: Try 3

Based on Dynamically call lambda based on stream input: Try 2 This fixes most of the points pointed out by @Morwenn. It has been generalized so anybody can call it. The only extra part needed by the ...
8
votes
4answers
355 views

n-dimensional Euclidean space calculation templates

I have been working with C++11 code that uses std::vector[] to store coordinates. Most often this code uses 2D or 3D but it occurred to me that it may be generally ...
10
votes
2answers
102 views

Dynamically call lambda based on stream input: Try 2

Originally asked here: Dynamically call lambda based on stream input The following version is based heavily on the answer provided by @iavr though I hope that I have done enough more to mkae it worth ...
7
votes
1answer
160 views

C++ template range

From a previous question I got an answer that included some template magic (that to be blunt was mind-boggling (as I could not understand it)). So I have been trying to achieve the same results ...
5
votes
2answers
1k views

Unique type ID in C++

I need to have an unique ID for any type in C++ for a variant type. Is this code reliable for getting the ID? I don't care to have same ID for same type between multiple runs. Sorry for ...
11
votes
3answers
552 views

Very basic tuple implementation

I've been messing with metaprogramming and variadic templates in C++, and I came up with this very primitive implementation of a tuple: ...
4
votes
0answers
175 views

Clone of Boost Variant

As part of learning C++, with special emphasis on C++11, I wanted to implement the equivalent of Boost's Variant (located here). My code is available at variant.hpp, with the current version given ...
4
votes
0answers
224 views

C++ class “overload” using variadic templates and wrapped function pointers

I'm using C++11 and I have the following problem (pseudo C++): ...
8
votes
2answers
199 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
111 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 ...
5
votes
0answers
241 views

Building a good C++11 template library - compile-time checked enum array

The task is to add data or values to members of a given enum class. The compiler should check, if a value for each enum member is available, and not just default construct empty values. It is a tool ...
3
votes
2answers
116 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 ...
3
votes
1answer
77 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
1k 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
356 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 ...
6
votes
1answer
162 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: ...
1
vote
1answer
557 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: ...
10
votes
1answer
2k 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
293 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: ...
11
votes
1answer
370 views

Variadic function with restricted types

I am designing a class which (among other things) acts as a vertex in an undirected graph. ...
10
votes
1answer
349 views

D2.0 mixin and template-heavy code - building a Silverlight clone

I've made a mock version of Silverlight in D2. It is meant to output html but since I don't know HTML yet, it's current output is not valid. HTML is not the reason I'm here though. The goal of my ...
5
votes
1answer
527 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 ...