Archive for the ‘meta’ Category
Metalists for fun and profit
Posted by: nadavrot on: 07/02/2010
- In: meta
- 9 Comments
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.
Compile time primality test
Posted by: rmn on: 27/01/2010
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.
Computing the level of indirection for pointer types
Posted by: rmn on: 25/10/2009
- In: meta
- 5 Comments
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.
Substitution failure is not an error, part II
Posted by: rmn on: 12/09/2009
- In: meta
- 2 Comments
As promised, this article continues and provides a thorough explanation of the previous post.
Substitution failure is not an error, part I
Posted by: rmn on: 11/09/2009
- In: meta
- 6 Comments
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.
Recent comments