Archive for the ‘meta’ Category

My name is Nadav Rotem and I am a guest blogger on this blog. I am here to write about metalists. Not metalists like Metallica or Iron Maiden, but meta-lists. Lists which are “template maiden”.

The First thing I am going to show you is how to create a data structure which is similar to a linked list. Next we are going to define the Push, Pop and Concat operations. After we have those, we will implement the Walsh transform (similar to FFT on integers) on our list. After that, we will use template templates to define generators to create lists. Finally we are going to implement the Map and Reduce operations on our lists. Let’s start.

Read the rest of this entry »


The powerful template mechanism of C++ allows us to write pretty complex Meta Functions, which are executed by the compiler during compilation. There are two basic types of meta-functions: one whose result is a type (mainly dealt with by Boost.MPL), and the other is a compile-time computation (which can result in any compile time constant). In this post we will review an example of the latter.

We would like to achieve a compile time boolean constant of the form is_prime<any constant number>::res. The problem with such meta programming task, in my opinion, is that it requires a functional programming mindset. Something that we, C++ programmers, aren’t necessarily used to. But I am sure we will be able to tackle it anyway.

Read the rest of this entry »

I’ve finally had a little time to advance with reading Alexandrescu’s book on Modern C++ design, and I’m absolutely blown away by the sheer awesomeness of its ideas. I highly recommend getting this book!

I would like to show just a little bit of what we can do with template specialization when it comes down to meta programming.

Read the rest of this entry »

As promised, this article continues and provides a thorough explanation of the previous post.

Read the rest of this entry »

Explanation on what is SFINAE can be found at wikipedia. I’ve tried to write my own explanation but ended up with the conclusion that it’s best described there, and I wouldn’t want to copy&paste stuff. If you have any question marks floating around your heads, please don’t hesitate to ask.

SFINAE is used alot in meta-programming. For example, you will be able to find many constructs in boost that are making use of this idea.

I’ve come across a pretty nice and complex use of SFINAE on stackoverflow the other day. The code below generates a templated class HasX<T>, whose member HasX<T>::value denotes whether the class T has a member (data or function) called x, or not. Let me introduce the code, and an explanation will follow.

Read the rest of this entry »