This is an update to the previous post about templating the Visitor pattern. Templated implementation of the Visitor Pattern for C++03 I won’t repeat the bulk of the post as the examples will be identical. The new code uses ‘variadic temples’ that were introduced with C++11, and as such, greatly simplifies the code required. Visitable […]
Implementing a moving average
Known by many names, such as as Cumulative Moving Average, Rolling Average, Running Average, Moving Mean or Rolling Mean, the object is to update an average value on receipt of a new value over a set window size. Example: Imagine we have accumulated 10 values and our window size is 10.[ 1, 2, 3, 4, […]
C++ wrapper for legacy C arrays
If you are writing in C++ you will sometimes be presented with an array defined by a section of C code. Using C++ you will have got used to having member functions to allow access to a container in a more error free fashion than raw C arrays. Using this template we can create a […]
The Embedded Template Library
Why did I start it? I wrote the Embedded Template Library (ETL), and all the others I have written over the years, because I’m lazy. Yes, lazy! But in a good way I believe. See here. Don’t Re-invent The Wheel I hate having to code yet another variation of the same thing in a slightly […]
There are four types of programmer
Their is a story about a German general that declared that there were four kinds of people, only three of which he wanted in his army. Here’s my take on it from a programmer’s angle. Intelligent Lazy Intelligent lazy people hate having to reinvent a solution to a problem that has already been solved. […]
Largest / Smallest. Part 2
In the last post i showed you how to implement a ‘Largest’ traits template using pre-C++11. In this post I will show you how to do the same using variadic templates. First we declare the ‘bare’ template. It tells the compiler that ‘Largest’ take an unknown number of template parameters. Next, we create helper templates […]
Largest / Smallest. Part 1
Sometimes, when multiple types are sent as template parameters, some information about the types needs to be interrogated to be able to configure another property of the template. The STL’s type traits header does a good job of supplying many of the more useful ones, but there is room for extension. Say, for instance, the […]
Templated implementation of the Observer Pattern
The purpose of this template is to simplify the creation of classes that implement the Observer Pattern and attempt to eliminate certain runtime errors by turning them into compile time errors. The pattern consists of two template classes. Observer and Observable. Observable The class derived from this will be observed by classes derived from Observer. It […]
Templated implementation of the Visitor Pattern
Introduction There are probably many of you out there who, like me, have investigated the possibilities that templates and template meta-programming can bring to your code. After having some success with templated image and image algorithm classes, I turned my attention to seeing whether some of the design patterns I use could be encapsulated in […]
Designing an efficient and low resource messaging framework. Part 3
In the last post I showed how to shrink the vtable overhead and reduce the coupling of the framework. This time I shall show how to reduce the vtable hit even further using another technique called the Curiously Recurring Template Pattern or CRTP. This oddly name pattern is a way of replacing runtime virtual calls […]
Recent Comments