ABSTRACT

This chapter discusses the basic methods involved in metaprogramming and compile-time computing. It starts with metafunctions and introduces the similarities and differences of functions used at compile time and runtime through some simple examples. The chapter discusses the basic writing rules of sequences, branches, and looping codes. Then the chapter also introduces a classic technique—the Curiously Recurring Template Pattern (CRTP). C++ metaprogramming is typically functional programming in which functions have a pivotal figure in the entire programming system. The functions here are different from those defined and used in general C++ programs and are closer to functions in the mathematical sense—mapping or transformation without side effects: with the same input, the results remain the same no matter how many times the function is called.