C++ has the ability to evaluate expressions at compile time, meaning that values are already calculated when the program executes. Even though metaprogramming has been possible since C++98; however, it was very complicated due to its complex template-based syntax. With the introduction of constexpr and, recently, if constexpr, metaprogramming has become much more similar to writing regular code.
This chapter will give you a brief introduction of compile-time expression evaluations in C++ and how they can be used for optimization.