Skip to content

constexpr and Compile-Time Computation

If the result of a computation can be determined at compile time, why wait until runtime? constexpr makes it possible to evaluate functions and variables at compile time, while consteval and constinit provide further hard guarantees for compile-time evaluation. In this chapter, we start with the basics of constexpr, understand the design constraints of literal types and constexpr constructors, master the new tools in C++20, and finally apply compile-time lookup tables, string processing, and design patterns in practice.

Chapter Contents

Built with VitePress