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

Stephen Kelly steveire at gmail.com
Sat Jul 2 12:26:02 CEST 2016

Thiago Macieira wrote:

> More to the point, Qt developers don't have to know the Standard Library.
> *I* don't and I don't have time or interest in learning it.

There is a big division within the C++ community. There is the Qt way and 
the non-Qt way, and they don't overlap.

The approach of many raw loops and no algorithms is taken often in Qt 
implementation (and documentation).

On the other side of the dividing line is people who value boost::irange, 
boost::indexed_range, boost::max_element and others.

As someone who 'crossed over' to the range/algorithm/stl way after starting 
at Ableton, I can say I prefer it greatly.

Here is a patch from me which fixes two bugs in one line of code (which I 
wrote several years previously):


Those kinds of bugs don't occur if you use algorithms instead of nested 
loops. Classes of bugs get eliminated:

 for (auto j = 0; j <= model->rowCount(); ++i) { // Double oops!


 for (auto row : boost::irange(0, model->rowCount()) { 


Yes, code could still mistakenly use `i` inside the loop, but that is a 
different class of bug which would be present in both cases (and the 
solution is more scoping by extracting named functions).



More information about the Development mailing list