Even having a lot a questions about this topic, I am having more and more problems. I think the problem is in understanding the meaning of certain words. All quotes below are from Cppreference
- What does 'discarded' mean in the text below? I understand 'discarded' as something never compiled/touched, something that, whatever it is (like random characters that would be errors), it won't interfere in the rest of the program.
In a constexpr if statement, the value of condition must be a contextually converted constant expression of type bool (until C++23)an expression contextually converted to bool, where the conversion is a constant expression (since C++23). If the value is true, then statement-false is discarded (if present), otherwise, statement-true is discarded.
- What 'instantiaded' mean ?
If a constexpr if statement appears inside a templated entity, and if condition is not value-dependent after instantiation, the discarded statement is not instantiated when the enclosing template is instantiated .
- What 'checked' mean? I understand that 'checked' means the code was totally compiled and verified for any possible error at that time.
Outside a template, a discarded statement is fully checked. if constexpr is not a substitute for the #if preprocessing directive: