void(?) unique_ptr<T>::emplace(Args &&... args) { *this = make_unique<T>(std::forward<Args>(args)...); }void(?) shared_ptr<T>::emplace(Args &&... args) { *this = make_shared<T>(std::forward<Args>(args)...); }
I've found really helpful in my own smart pointer classes to have something like .create(Args &&..args) method that creates an object for an owning shared pointer without the necessity for repeating the type in the make_* non-member function.It's a shame that standard smart pointers don't have such method, so in order to create a value you always need to repeat the type name, while it is contained in the pointer type itself.
void(?) unique_ptr<T>::emplace(Args &&... args) { *this = make_unique<T>(std::forward<Args>(args)...); }void(?) shared_ptr<T>::emplace(Args &&... args) { *this = make_shared<T>(std::forward<Args>(args)...); }What do you think? Are there reasons not to add such methods? Or was this discussed / proposed already?
| From: 'Thomas Köppe' via ISO C++ Standard - Future Proposals Sent: Tuesday, October 31, 2017 10:33 AM To: ISO C++ Standard - Future Proposals Reply To: std-pr...@isocpp.org Subject: [std-proposals] Re: Add .emplace() method to std::unique_ptr and std::shared_ptr like it is in std::optional. |