I am trying to find out if there is an increase in performance for creating objects with constexpr instead of the usual one.
Here is the code snippet for constexpr .
class Rect { const int a; const float b; public: constexpr Rect(const int a,const float b) : a(a),b(b){} }; int main() { constexpr Rect rect = Rect(1,2.0f); }
And without constexpr .
class Rect { int a; float b; public: Rect(int a, float b) : a(a),b(b){} }; int main() { Rect rect = Rect(1,2.0f); }
I expected that constexpr would be much less code for constexpr , since the memory had to be initialized at compile time.
Am I using constexpr correctly? And if that is not the case, can you use constexpr to create objects at compile time and then use them at no cost to the runtime?
Thanks!
source share