Reputation: 1437
Despite reading through some StackOverflow posts (this and this) and cppreference pages, I cannot figure out how a non-static constexpr
local variable would be beneficial compared to a static constexpr
one.
The only difference I can see is that each invocation would have its own instance, but since it's a constexpr
I don't see the practical advantage here (since, if I understand correctly, that'd cause each instance to be identical and immutable, making multiple instances simply redundant).
Or, to argue from another point: Since non-static constexpr
locals are initialized at (every) function invocation, there is no advantage to a simple const
local, despite that it may be used for compile-time evaluations. But when they are needed for compile-time evaluation, there's no point in making them not static.
So my question is: How is my argument deficient, and in what cases would a non-static constexpr
local variable be reasonable and possibly be the best choice?
Upvotes: 6
Views: 670