Why is there no
std::unique_ptr<SomeUserDefinedType> p(new SomeUserDefinedType(1, 2, 3));
auto p = std::make_unique<SomeUserDefinedType>(1, 2, 3);
template<typename T, typename... Args>
std::unique_ptr<T> make_unique(Args&&... args)
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
Herb Sutter, chair of the C++ standardization committee, writes on his blog:
That C++11 doesn’t include
make_uniqueis partly an oversight, and it will almost certainly be added in the future.
He also gives an implementation that is identical with the one given by the OP.
std::make_unique now is part of C++14.