似乎在 C++20 中,我们获得了一些额外的智能指针实用函数,包括:
template<class T> unique_ptr<T> make_unique_for_overwrite();
template<class T> unique_ptr<T> make_unique_for_overwrite(size_t n);
Run Code Online (Sandbox Code Playgroud)
和std::make_sharedwith 一样std::shared_ptr。为什么不是现有的功能:
template<class T, class... Args> unique_ptr<T> make_unique(Args&&... args); // with empty Args
template<class T> unique_ptr<T> make_unique(size_t n);
Run Code Online (Sandbox Code Playgroud)
足够的?现有的不使用对象的默认构造函数吗?
注意:在这些函数的早期提案中,名称是make_unique_default_init().