make_unique teaches users "never say new/delete and new[]/delete[]" without disclaimers.
make_unique
new
delete
new[]
delete[]
make_unique shares two advantages with make_shared (excluding the third advantage, increased efficiency). First, unique_ptr<LongTypeName> up(new LongTypeName(args)) must mention LongTypeName twice, while auto up = make_unique<LongTypeName>(args) mentions it once.
make_shared
unique_ptr<LongTypeName> up(new LongTypeName(args))
LongTypeName
auto up = make_unique<LongTypeName>(args)
make_unique prevents the unspecified-evaluation-order leak triggered by expressions like foo(unique_ptr<X>(new X), unique_ptr<Y>(new Y)). (Following the advice "never say new" is simpler than "never say new, unless you immediately give it to a named unique_ptr".)
foo(unique_ptr<X>(new X)
unique_ptr<Y>(new Y))
unique_ptr
make_unique is carefully implemented for exception safety and is recommended over directly calling unique_ptr constructors.
std::make_unique
1.4m articles
1.4m replys
5 comments
56.9k users