June 25, 2016
Soon, after writing my first meta programs with C++ templates, i realized, that certain programming patterns lead to sky rocketing compile times.
I came up with rules of thumb like “Prefer pattern matching over if_else_t”, and “Prefer nested type lists over variadic type lists”.
But i did not know how much faster which pattern is, i just knew about tendencies.
Finally, i sat down to write some compile time benchmarks, and this blog posts presents the results.
June 24, 2016
In some situations, it can be useful ot generate sequences of numbers at compile time.
This article shows how to generate integer sequences with C++ templates, and gives an example how to use it.
June 16, 2016
This article completes a series which aims at explaining how to implement a Brainfuck Interpreter, which runs at compile time, because it is a template meta program.
May 15, 2016
Turing Machines consist of a tape with memory cells, a tape reader like cassette drives and a program table.
Implementing the tape drive part with an array and a pointer is a trivial thing to do with imperative programming languages.
It becomes more interesting when learning purely functional programming, especially in the context of template meta programming in C++.
As a preparation for the next article, i will show how to implement a turing tape based on type lists, usable at compile time.
May 14, 2016
Type lists are an important way to represent ordered and unordered sets of types at compile time.
These types can be real structure- or class types bundling runtime algorithms etc., but they can also convey actual data at compile time.
In order to apply certain compile time processing to data, this data needs to be transformed from and to other representations, which can be provided by the programmer and consumed by run time programs.
This article shows how to transform back and forth between strings and character type lists.
May 8, 2016
Homogenuous data in purely functional programs is typically managed in lists.
Items can be appended or prepended to lists, different lists can be concatenated.
Lists can be filtered, transformed, mapped, reduced, etc.
Having all this nice stuff as a template meta library is quite an enabler for complex compile time meta programs.
May 5, 2016
C++ template meta programs are at first really hard to read.
This is because the template mechanism accidentally became turing complete, although it was invented to enable for type-agnostic programming of generic algorithms.
However, now the world knows that the C++ template part of the language is turing complete, people started writing full programs in it, and it enhances the power and flexibility of libraries quite a lot.
This article aims to explain some very basic things one needs to know about the C++ template meta programming language, in order to be able to do things with it, or even understand foreign programs.
March 23, 2016
In both C and C++, it is not a sane idea to hold a reference (or a pointer in C) to a temporarily created object, as the reference is quickly dangling as soon as the assignment is done.
But actually, C++ provides an interesting feature, where the life time of a temporary object can be extended to the life time of the reference which points to it.
March 18, 2016
What does actually happen, if an exception is thrown somewhere in the middle of a C++ program, but there is no try-catch clause which handles it?
The program gets terminated.
That is fine in general, but what happens to all objects which need to be properly destructed?
February 27, 2016
In order to use polymorphy, virtual functions are the way to go in C++.
They are nice and easy to use.
However, polymorphy is not always needed at actual runtime.
If it is only used to separate generic from specific functionality in order to have a common interface and avoid code duplication, the cost of having indirection introduced by vtables might not be desired.
This article shows how to use the CRTP in order to get the compile time advantages of polymorphy, without using virtual methods.