-
Book Overview & Buying
-
Table Of Contents
Software Architecture with C++ - Second Edition
By :
Template metaprogramming allows us to write C++ code that is executed during compile-time as opposed to the usual runtime execution. The constexpr keyword, which was added in C++11, allows us to make more extensive use of compile-time logic, and the consteval keyword from C++20 aims to give us greater control over the way the code is evaluated during compilation.
One of the problems with compile-time programming is that there is no easy way to test it. While unit testing frameworks for execution time code are abundant (as we just saw), there are not that many resources regarding compile-time programming. Part of this may stem from the fact that compile-time programming is still considered complicated and only aimed at experts.
However, just because something isn’t easy doesn’t mean it is impossible. Just like execution time tests rely on assertions being checked during runtime, you can check your compile-time code for correct behavior...