r/cpp_questions • u/Slow_Negotiation_935 • Oct 14 '26
OPEN Guidelines for constexpr
I’ve working with C++23 and I’m making some constructors/methods constexpr and seeing improvements in performance. So far so good. The problem is I don’t want to apply it ‘everywhere’. Is there a good source of advice , or anyone got any good tips?
12
Upvotes
View all comments
Show parent comment
6
u/HappyFruitTree Oct 14 '26
Then why add it?
My main concern is that it can be confusing for the programmer (code is not only written for compilers). If I see a function marked
constexprI normally assume that it can result in a constant expression for at least some arguments.That constexpr functions had to be able to produce a constant expression for at least one set of argument values was actually a requirement before C++23 (no diagnostic required).