Why does C++11 have `make_shared` but not `make_unique`

C++C++11

C++ Problem Overview


> Possible Duplicate:
> make_unique and perfect forwarding

Why does C++11 have a make_shared template, but not a make_unique template?

This makes code very inconsistent.

auto x = make_shared<string>("abc");
auto y = unique_ptr<string>(new string("abc"));

C++ Solutions


Solution 1 - C++

According to Herb Sutter in this article it was "partly an oversight". The article contains a nice implementation, and makes a strong case for using it:

template<typename T, typename ...Args>
std::unique_ptr<T> make_unique( Args&& ...args )
{
    return std::unique_ptr<T>( new T( std::forward<Args>(args)... ) );
}

Update: The original update has been updated and the emphasis has changed.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionŠimon T&#243;thView Question on Stackoverflow
Solution 1 - C++juanchopanzaView Answer on Stackoverflow