O'Reilly logo

Discovering Modern C++: An Intensive Course for Scientists, Engineers, and Programmers by Peter Gottschling

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 5. Meta-Programming

Meta-Programs are programs on programs. Reading a program as a text file and performing certain transformations on it is certainly feasible in most programming languages. In C++, we can even write programs that compute during compilation or transform themselves. Todd Veldhuizen showed that the template type system of C++ is Turing-complete [49]. This means that everything computable can be calculated in C++ at compile time.

We will discuss this intriguing asset thoroughly in this chapter. In particular, we will look at three major applications of it:

• Compile-time calculations (§5.1);

• Information about and transformations of types (§5.2); and

• Code generation (§5.3–§5.4).

These techniques allow us to make the examples ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required