I understand that std::is_constant_evaluated()
was useful to determine compile time evaluation in C++20.
But since C++23 we have if consteval
.
However there is no mention of deprecation for std::is_constant_evaluated()
.
Is there any practical usage for it starting from C++23 ?
Quoting from the paper:
One of the questions that comes up regularly in discussing this paper is: if we had
if consteval
, we do we even needstd::is_constant_evaluated()
, and can we just deprecate it?This paper proposes no such deprecation. The reason is that this function is actually still occasionally useful (as in the previous section). If the standard library does not provide it, users will write their own. We’re not concerned about the implementation difficulty of it - the users that need this will definitely be able to write it correctly - but we are concerned with a proliferation of exactly this function. The advantage of having the one
std::is_constant_evaluated()
is both that it becomes actually teachable and also that it becomes warnable: the warnings discussed can happen only because we know what this name means. Maybe it’s still possible to warn onif constexpr (your::is_constant_evaluated())
but that’s a much harder problem.And note that libstdc++ already has some uses that do require the function form.
Edit: Even though I had specific anchored github links there and not just to master
, those "some uses" both point to lines that... are not actual uses of the form I was talking about. Not sure what happened there...