As far as I understand, C++14 introduced std::make_unique
because, as a result of the parameter evaluation order not being specified, this was unsafe:
Every use of new
has to be extra carefully audited for lifetime correctness; does it get deleted? Only once?
Every use of make_unique
doesn't for those extra characteristics; so long as the owning object has "correct" lifetime, it recursively makes the unique pointer have "correct".
Now, it is true that unique_ptr
is identical in all ways1 to make_unique
; it just requires a simpler "grep your source code for all uses of new
to audit them".
1 actually a lie in the general case. Perfect forwarding isn't perfect, {}
, default init, arrays are all exceptions.