Metaprogramming is the act of writing programs that run during the compilation of an ordinary program. Most metaprograms use templates to operate on types, but you can also write constexpr functions to compute values at compile time. Metaprogramming requires a different style than ordinary programming, and you will find yourself calling upon almost all the programming techniques you have learned so far.

Use constexpr for Compile-Time Values

In C++ 03, the only way to work with numeric values at compile time was to use templates and metaprogramming. In C++ 11, a better way is to use constexpr functions. To compare ...

Get Exploring C++ 11, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.