make_unique
One of the smallest additions is actually great in its impact. It’s
make_unique:
- auto u = make_unique<some_type>( constructor, parameters, here );
The reason
make_unique has important impact is that now we can teach C++ developers to mostly never use explicit new again. In C++11 we already could teach to never use raw pointers and explicit delete again, except in rare cases that are hidden inside a class in order to do something like implement a low-level data structure. However, we could not teach to never write new because although make_shared was provided to create a shared_ptr, newwas still needed to create a unique_ptr. Now, instead of “new”, write make_unique or make_shared.
With draft C++14, we can say simply: Don’t use raw pointers,
new and delete, except rarely when implementing low-level data structures. Allocate with make_unique or make_shared, use weak_ptr where appropriate to break cycles, and don’t worry about dangling pointers in C++ again.
From http://isocpp.org/blog/2013/04/trip-report-iso-c-spring-2013-meeting