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
0answers
40 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 ...
5
votes
0answers
36 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
95 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
81 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
100 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++. ...
12
votes
0answers
96 views

C++ SQL wrapper/Connection

Working on my SQL project at last. The concept is easy to use and integrate SQL into C++. ...
11
votes
1answer
107 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
92 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
80 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
186 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
193 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
162 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 ...
4
votes
1answer
159 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
0answers
99 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
30 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
64 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 ...
10
votes
3answers
292 views

Meta-programming template for collection statistics

I find that I often want to calculate summary statistics from collections of data and decided to create a template to do that. I'm interested in a general review, but I also have some specific ...
3
votes
0answers
217 views

Compile Time Constant Map

I have implemented this compile time map as a way of learning templates and constexpr classes: ...
6
votes
1answer
95 views

Variadic template for concisely defining a tuple whose components are all the same type

C++11 provides a std::tuple template, but it requires the types of all the fields to be listed individually, which is inconvenient if there are many fields and ...
1
vote
0answers
55 views

Counting words in files - follow-up 4

Previous question: Counting words in files - follow-up 2 Continuation of the meta programming template version of counting words. Inspired by example of pirntf ...
2
votes
0answers
66 views

Counting words in files - follow-up 2

Previous question: Counting words in files - follow-up I have fixed punctuation problems in my previous code by using template, because it is easy to understand and my focus on template mechanism. ...
2
votes
3answers
190 views

Use of macros to aid visual parsing of SFINAE template metaprogramming

I've recently been introduced to SFINAE to solve the problem of unwanted promotion precedence. i.e. I was hoping to catch integer types with Foo::Foo(long) and ...
5
votes
1answer
51 views

“event_foo” method event system in D

The goal is to be able to call an event_<name> method on an object if it implements it, or otherwise do nothing, without needing to explicitly define and ...
6
votes
2answers
960 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
309 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 ...
7
votes
2answers
339 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
98 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
403 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 ...
10
votes
1answer
385 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
247 views

Function object passing for a task scheduler

Here is my full implementation of a generic Functor-like class: ...
5
votes
2answers
333 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 ...
8
votes
2answers
2k views

std::tuple foreach implementation

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

Plugin system for calling methods

I have a small "plugin system" (I'm not sure this is the 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
202 views

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

On SO, I asked for a way to do it without variadics. I also provided a typical "normal" implementation with variadics: ...
5
votes
1answer
164 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
402 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
109 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
290 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
2k 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
99 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 ...
11
votes
5answers
1k 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
139 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
268 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
4k 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
2k 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: ...
10
votes
1answer
342 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 ...
5
votes
0answers
501 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
530 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 ...
7
votes
0answers
452 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
133 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 ...