The C-Preprocessor is a very powerful mechanism, which offers many different features. One of these features is called Variadic macros: macros that accept a varying number of arguments. It is interesting to note at this point, that such Variadic macros, despite being part of the C99 Standard, are not part of the C++ Standard at [...]
Archive for the ‘techniques’ Category
Variadic macro to count number of arguments
Posted in techniques on 17/07/2010 | 10 Comments »
Memoization
Posted in techniques on 07/01/2010 | 10 Comments »
Memoization is essentially a fancy name for caching results for future use. A generalization of dynamic programming, if you will. While I am certain most of us use it one way or another, in many occasions, it is usually through an Ad hoc implementation.. One that is only suitable for the specific, current, use case. [...]
Tag dispatching
Posted in techniques on 03/01/2010 | Leave a Comment »
Tag dispatching is a technique for compile time dispatching between a few overloaded functions by using the properties of a type. This technique usually involves some kind of type traits.
Implementing assignment operator using copy constructor
Posted in techniques on 04/09/2009 | 7 Comments »
Many times we are required to define both a copy constructor and an assignment operator (for example: according to the rule of three, if we need one we are likely to need the other). The two will probably share a pretty common code, if not exactly the same. So what we will do in many [...]
Computations at compile time
Posted in techniques on 13/08/2009 | Leave a Comment »
The C++ template mechanismĀ is a very powerful tool. Besides its great ability of code generation, it can also be used to make useful computations at compile time. Let us introduce such an example.