Why doesn't Qt support move-only QList?

I want to ask this question again despite Why Qt container classes do not allow moveable, non-copyable item types? ... I read the following expression from a third party QtCore developer Thiago (linked to the linked answer to a Stackoverflow question):

Will not be implemented. Copyability is a requirement due to implicit sharing.

I don't understand this statement: Copyability is a requirement for implicit exchange, I understand this part. But why is it meant to share the requirement for the non-copyable QList<T>

?

QList

already has move and move-assign-operator constructors, so assuming building QList<T>

from another temporary QList<T>

will not apply implicit sharing, but rather move the base d-pointer, in which cases implicit sharing occurs when only copying / assigning the temporary / rvalue QList

around?

+3


source to share


2 answers


Possibly because QLists are only marked as reentrant and not thread safe ( definition ).

I haven't looked at the source code, but I think the overhead of maintaining a streamed QList exceeds the cost of supporting a regular user (of course, these are just fake excuses: P).



When T is a pointer or reference, it could mean that multiple memory spaces need to be synchronized when the object in the list changes - this is outside the scope of Qt. I can also imagine it getting tricky for Qt if there is some factory in the instance objects of the main thread. Or when an object owns links / pointers to streams or callbacks.

You probably shouldn't be answering any of your questions, but that was more than a comment.

0


source


All Qt container classes are implicitly shared. This is not negotiable. How else do you want the signal that the QList emits by value to connect to multiple slots? With no move semantics or no implicit exchange, you will end up with many copies flying around. With move semantics, everyone but the first slot will get an empty (well, unspecified moved from) list. So implicit sharing becomes a necessity in the case of the rest of their API data, which is too much in cost, because why not? It is still implicitly split.

To summarize: I don't think Qt wants to make exceptions for the implementation of any of its containers, for example, make the move list only implicitly shared, whereas any other list will have this implicit exchange. The difference in side effects is too great.



Also note that, at least when reading between the lines, they move more towards std containers, although there will be more of those elements in the API than anyone else ...

0


source







All Articles