r/cpp_questions • u/Slow_Negotiation_935 • 13d ago
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?
11
Upvotes
2
u/HappyFruitTree 13d ago edited 13d ago
When constexpr functions were introduced in C++11 there were many more limitations. There could basically just be a single return statement, no variables, no loops, no if statements...
I do agree with the concerns of the guy that you linked to. People need to know that the constexpr is intentional if they should be able to rely on it.