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

QList: support move-only types



    • Task
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • None
    • None


      Although it's possible to construct a QList with move-only element types, it's not usable, since most of the operations on a QList require its elements to be copyable, even if they have overloads taking rvalue refs, and no copying is done in practice (this is because QArrayDataPointer internally does a runtime check, to decide if copy or move operations should be used, see e.g. https://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/tools/qarraydatapointer.h?h=6.4.0#n225). For example: 

      QList<std::unique_ptr<int>> list; // Ok
      list = std::move(anotherList); // Ok
      list.push_back(std::move(ptr); // Doesn't compile
      l.emplace_back(new int (5)); // Doesn't compile
      list.removeAt(0); // Doesn't compile
      list.reserve(); // Doesn't compile
      // etc.

      As far as I understand, the main limitation is that QList (and other Qt containers) is designed to support implicit sharing. However, QList with move-only elements can't be copied in any case, so no implicit sharing should be required. If we disable implicit sharing for a QList with move-only element types at compile time, it should be possible to support move-only types. 


        Issue Links

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



              cnn Qt Core & Network
              sonakur Sona Kurazyan
              Vladimir Minenko Vladimir Minenko
              Alex Blasche Alex Blasche
              0 Vote for this issue
              2 Start watching this issue



                Gerrit Reviews

                  There are no open Gerrit changes