| Defined in header |
constexpr bool is_constant_evaluated() noexcept;
Detects whether the function call occurs within a constant-evaluated context. Returns
true if the evaluation of the call occurs within the evaluation of an expression or conversion that is manifestly constant-evaluated; otherwise returns
The following expressions (including conversions to the destination type) are manifestly constant-evaluated:
To test the last two conditions, compilers may first perform a trial constant evaluation of the initializers. It is not recommended to depend on the result in this case.
int y; const int a = std::is_constant_evaluated() ? y : 1; // Trial constant evaluation fails. The constant evaluation is discarded. // Variable a is dynamically initialized with 1 const int b = std::is_constant_evaluated() ? 2 : y; // Constant evaluation with std::is_constant_evaluation() == true succeeds. // Variable b is statically initialized with 2
true if the evaluation of the call occurs within the evaluation of an expression or conversion that is manifestly constant-evaluated; otherwise
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.