Stephan Lavavej has submitted a proposal to the C++ Standards committee for make_unique (the std::unique_ptr equivalent to std::make_shared for std::shared_ptr).
make_unique’s presence in the Standard Library will have several wonderful consequences. It will be possible to teach users “never say
new/delete /new/delete” without disclaimers. Additionally,
make_uniqueshares two advantages with
make_shared(excluding the third advantage, increased efficiency). First,
unique_ptr<LongTypeName> up(new LongTypeName(args))must mention
auto up = make_unique<LongTypeName>(args)mentions it once. Second,
make_uniqueprevents 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
It’s a really useful utility as demonstrated in this video.