Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-69069

Allow QSharedPointer to take a std::unique_ptr&&

    XMLWordPrintable

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());

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            Unassigned Unassigned
            benfrantzdalefl benfrantzdalefl
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes