[Development] qMoveToConst helper for rvalue references to movable Qt containers?

Giuseppe D'Angelo giuseppe.dangelo at kdab.com
Mon Oct 22 21:45:40 CEST 2018


Hi,

Il 22/10/18 21:40, André Pönitz ha scritto:
>> Which just shows it's working as intended.
> I have (a) no example that triggers obviously bad behaviour and (b)
> a bad gut feeling nevertheless.

What bad behaviour are we referring to here?

> 
> The problem is that a 'move' could be a 'swap' in practice, with the
> to-be-destroyed object held 'for a while', effectively turning C++'s
> rather deterministic destruction behaviour into something resembling
> garbage collection.
> 
> I wouldn't be surprised if one can cause real problems with 'random'
> destruction orders on non-memory resources, like files. Simple memory
> might be safe(r), as releasing order does typically not matter.

Oh, it absolutely does. That's why in Qt we implement move assignment in 
terms of pure swap if and only if the only resource that a container 
holds is memory (e.g. QString, QByteArray). For all other cases (e.g. 
QVector) we implement move assignment as move-and-swap, to be sure that 
resources are deterministically destroyed when the move happens.

My 2 c,

-- 
Giuseppe D'Angelo | giuseppe.dangelo at kdab.com | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - The Qt, C++ and OpenGL Experts

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4007 bytes
Desc: Firma crittografica S/MIME
URL: <http://lists.qt-project.org/pipermail/development/attachments/20181022/6626fae0/attachment.bin>


More information about the Development mailing list