Entries by Rainer Grimm

Template Metaprogramming – How it Works

In my last post, “Template Metaprogramming – How it All Started“, I wrote about the roots of template metaprogramming. I presented the hello world of template metaprogramming: calculating the factorial of a number at compile time. In this post, I will write about how template metaprogramming can modify types at compile time.

Template Metaprogramming – How it All Started

Metaprogramming is programming on programs. C++ applies metaprogramming at compile time. It started in C++98 with template metaprogramming, was formalized in C++11 with the type-traits library, and since C++11 has steadily improved. The main driving force is constant expressions. In this post, I want to write about its roots.

Automatic Return Type (C++98)

Depending on the used C++ standard, there are different ways to return the correct return type of a function template. In this post, I start with traits (C++98), continue in my next post with C++11/14, and end with concepts (C++20).

Dependent Names

A dependent name is essentially a name that depends on a template parameter. A dependent name can be a type, a non-type, or a template parameter. To express that a dependent name stands for a type or a template, you have to use the keywords typename or template.