Details
-
Task
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
None
-
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
- blocks
-
QTBUG-127423 QFuture::unwrap() doesn't support non-copyable types
-
- Reported
-
- is required for
-
QTBUG-87084 Improve support of move-only types in QtConcurrent
-
- Open
-