Below are answers to questions in D2: Core Language — if constexpr, std::is_constant_evaluated(), and if consteval . Q1: Assuming the user enters 10, what values will this program print, and why? The program will print 20 in both cases. Despite the temptation to assume that if constexpr will allow to distinguish compile time and runtime execution, that is not really the case. Function constexpr int Calculate(int value) can be called at either compile time or runtime, however condition if constexpr is always evaluated during compile time. constexpr int compileTime = Calculate(10); must be evaluated as a constant expression during compile time because variable compileTime declared as constexpr . All necessary information is available. On the other hand int runtime = Calculate(input); can't be evaluated during compile time, since input is not known then. However, even for a runtime call, the condition if constexpr (std::is_cons...
First of all, code doesn't compile. error: call of overloaded 'processB(int)' is ambiguous It kind of suggests that the code is ill-formed. Answer to the first question. Before I jump into further explanations, I would suggest 2 sources to look at: CppReferences page - Constraints and Concepts (C++20) CppCon video - BackToBasics: Concepts Cpp reference article covers lots of ground and goes into great detail about Concepts. However, the language and examples used are sometimes hard to understand. That's where video comes in; Nicolai Josuttis's explanations of Concepts are great. Going back to the questions in the initial article D1: Core Language — Concepts, Constraint Subsumption, and Overload Resolution. Code, as I already mentioned, is ill-formed and doesn't compile. Let's try to understand why. Logically, we have declared similar concepts. SignedA and SignedB essentially define the same list of requirements for the fun...