//******************************************************** // The following code example is taken from the book // C++20 - The Complete Guide // by Nicolai M. Josuttis (www.josuttis.com) // http://www.cppstd20.com // // The code is licensed under a // Creative Commons Attribution 4.0 International License // http://creativecommons.org/licenses/by/4.0/ //******************************************************** #include "consteval2.hpp" #include #include int main() { int i = 42; // using the square functions at runtime with runtime value: std::cout << squareR(i) << '\n'; // OK std::cout << squareCR(i) << '\n'; // OK //std::cout << squareC(i) << '\n'; // ERROR // using the square functions at runtime with compile-time value: std::cout << squareR(42) << '\n'; // OK std::cout << squareCR(42) << '\n'; // OK std::cout << squareC(42) << '\n'; // OK: square computed at compile time // using the square functions at compile time: //std::array arr1; // ERROR std::array arr2; // OK: square computed at compile time std::array arr3; // OK: square computed at compile time //std::array arr4; // ERROR }