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 ...
Get Discovering Modern C++: An Intensive Course for Scientists, Engineers, and Programmers now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.