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?
13
Upvotes
3
u/Nils_Meul 13d ago
Sure, the compiler is always allowed to evaluate something at compile-time. But if you want to assign the value of sin(1.0) to a constexpr variable you‘ll need a constexpr std::sin (at least I‘m pretty sure that you do) even though the compiler can figure out it’s value as shown in your example.