[Development] HEADS UP: Don't use QList, use Q_DECLARE_TYPEINFO

Marc Mutz marc.mutz at kdab.com
Mon Jul 27 11:16:29 CEST 2015


On Monday 27 July 2015 00:27:18 Kevin Kofler wrote:
> It doesn't switch the stuff it actually guarantees:

That sentence is perfectly correct.

But here's the catch: The docs guarantee _a certain implementation_, incl. the 
switching. The problem is that the conditions under which the switch occurs 
are quite hard for non-experts to check.

This is the beauty of the STL: without mentioning the actual implementation 
anywhere, its containers have such tailor-made guarantees that effectively only 
one implementation possibility is left (they even rule out CoW without 
mentioning it!).

But since the STL doesn't specify any implementation, if research finds a data 
structure that meets those guarantees, the new structure automatically becomes 
permissible.

This is what made std::make_shared's optimisation possible, e.g.

Qt containers are not like that. QList docs say exactly how it's implemented, 
but not exactly what it guarantees. Thus, coming to depend on details of the 
implementation is a perfectly reasonable thing to do for a developer. It's 
documented, after all, if only indirectly.

Quite some code in QtBase alone already depends on the de-facto guarantee of 
stable references, among them, just off the top of my head:

- QDataWidgetMapper
- QToolBox
- one of the lists in QMime*
- QList<QMakeLocalFileName> in qmake

Thanks,
Marc

-- 
Marc Mutz <marc.mutz at kdab.com> | Senior Software Engineer
KDAB (Deutschland) GmbH & Co.KG, a KDAB Group Company
Tel: +49-30-521325470
KDAB - The Qt Experts



More information about the Development mailing list