How can we dynamically allocate at compile time? Does the constexpr operator new just allocate memory on the stack?
There is no constexpr new operator.
Since C++20, you can use new operator in constexpr expressions in the condition that you only use a replaceable global allocation function (it means that you don't use a placement new or user-defined allocation function) and that you deallocate the data in the same expression.
So, in your final program, this does not allocate memory, since you end up just with the final result of your constexpr expression.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With