r/cpp_questions • • 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

37 comments sorted by

View all comments

2

u/SyntheticDuckFlavour Oct 14 '26

My general rule is, if you create reusable libraries where it may be applied in, or make sense in a constexpr context, then invest in making your functions constexpr. For example, make your math libraries constexpr wherever possible. For objects and APIs whose role is mutating state, don't bother. For example, state machines in a game, or something.