Details
-
Suggestion
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
None
-
None
Description
Proposal: Add this c'tor to QSharedPointer:
template<class Y, class Deleter>
QSharedPointer(std::unique_ptr<Y,Deleter>&& r) : QSharedPointer(r.release(), r.get_deleter()) {}
(I think the implementation is a little different from that since QSharedPointer(r.release(), r.get_deleter()) could throw; basically the implementation would just ape the one in std::shared_ptr's similar c'tor.)
Rationale:
With C++11's rvalue references and unique_ptr, factory methods can return a std::unique_ptr<T> instead of a T*. I can construct a QSharedPointer<T> from that like this:
std::unique_ptr<T> foo(); // Factory
...
QSharedPointer<T> p(foo().release());
With this change that would become
QSharedPointer<T> p(foo());