The answer to this question from @Vittorio Romeo explains constinit
very well. In his answer, the following is mentioned:
constexpr
is not equivalent toconst constinit
, as the former mandates constant destruction, while the latter doesn't.
Although pretty clear, I fail to see any practical use of this. In which case would const constinit
be used, but constexpr
could not. In any case that I can think of, for any type T
that can be constinit
and cannot be changed during runtime via const
, constant destruction should be a trivial restriction to add. Am I missing something?
If you have a dependency on external code that you cannot change for whatever reason, and it looks like this
This will mean that
A
is not a literal type because it doesn't have aconstexpr
destructor (most likely an oversight). It could however be constructed at compile time and therefore be aconstinit
.