3 ms·
> In real life, there’s basically no reason ever to use constexpr on a stack variable; you’ll use it only on globals or as part of the set phrase static constex
by elteto 3y ago
> In real life, there’s basically no reason ever to use constexpr on a stack variable; you’ll use it only on globals or as part of the set phrase static constexpr.
Hmm… this is just unnecessarily dogmatic. I use constexpr all the time, for example, for local numerical constants that don’t need to be a global.
- Thorrez 3y agoWhy not use a static local constexpr? That seems like it would be faster to me due to not needing to allocate stack space and copy the value to the stack. You still get the benefit of not needing a global.
- elteto 3y agoIf the variable is numeric, and const or constexpr, and you have -O1 or higher enabled, then the compiler will optimize it away. I don’t think static would add anything under these conditions.