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"));
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With