Meta-Programming using C++ templates

A while ago, at the beginning of the current semester, I posted a source code snippet which demonstrated the very basics of a technique called meta-programming. The term “meta programming” describes the creation of programm code that produces programm code itself during compile-time.

In C++ mainly features of template programming and template specialization are used to create meta programms. The meta programms featured in the code snippet calculates sums of numbers from 1 to a given parameter or the value of the fibonacci-sequence to a given index.

The evaluation of the fibonacci numbers for example is executed during compile-time which results in a constant runtime, not depending on the index for the sequence to be evaluated. Of course this technique can only be used to solve static problems.


About this entry