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

QList: support move-only types

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Reported
    • Priority: Not Evaluated
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Labels:
      None

      Description

      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. 

        Attachments

          Issue Links

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

            Activity

              People

              Assignee:
              cnn Qt Core & Network
              Reporter:
              sonakur Sona Kurazyan
              PM Owner:
              Vladimir Minenko Vladimir Minenko
              RnD Owner:
              Alex Blasche Alex Blasche
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:

                  Gerrit Reviews

                  There are no open Gerrit changes