[Development] Use of Standard Library containers in Qt source code

Christian Kandeler christian.kandeler at qt.io
Mon Jul 4 09:59:44 CEST 2016

On 07/01/2016 08:36 PM, Thiago Macieira wrote:
> For some time now, we've had a flurry of changes to Qt source code that uses
> the Standard Library's containers and algorithms, in the name of performance
> and often code size gains.
> I'm not disputing that there is a gain. But I am wondering about the trade-off
> we're making with regards to readability. For example, I was just reviewing
> this code:
>     if (d->currentReadChannel >= d->readHeaders.size()
>         || d->readHeaders[d->currentReadChannel].empty()) {
>         Q_ASSERT(d->buffer.isEmpty());
> The use of the Standard Library member "empty" is highly confusing at first
> sight because it does not follow the Qt naming guidelines. It's even more
> confusing because the next line has "isEmpty". When I read this code, I had to
> wonder if that "empty" was a verb in the imperative, meaning the author was
> trying to remove all elements from the container.

I must admit I don't see a problem here. We are not talking about some 
random third-party library that people are pulling in gratuitously, but 
about the Standard Library, an integral part of C++ that every developer 
should be at least generally familiar with.
Having said that, I personally follow the "use Qt types by default" 
approach, but should we really regard STL containers as dangerous 
intruders that need to be kept out if at all possible?


More information about the Development mailing list