0
Where make_unique is better than unique_ptr(raw pointer)
Hi If both (unique_ptr and make_unique) have same output like i have in this code, what's the advantage of make_unique. https://sololearn.com/compiler-playground/cnxp9hb8AB1E/?ref=app
4 Réponses
+ 2
make_unique is a fundamental improvement for modern C++ development and it provides:
Crucial exception safety guarantees.
More concise and readable code.
Reduced redundancy.
Potential minor performance benefits.
+ 1
reading a reddit topic similar to this question gave me this link as to why make_unique was added later than make_shared:
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3588.htm
+ 1
Let's add the cppreference document
https://en.cppreference.com/w/cpp/memory/unique_ptr/make_unique
0
This all points look good @BroFar but details would help a lot. It provides safety guarantee , but when and which case? can we demonstrate it with failure for unique_ptr(raw pointer) constructor and good for make_unique? What redundancy is removed by make unique? Which performance benefit from make_unique? I am aware that make_shared allocate heap memory once making it effective, but not sure about performance gain of make_unique