[Development] Important recent changes in QList/QString/QByteArray

Thiago Macieira thiago.macieira at intel.com
Tue Sep 1 20:57:47 CEST 2020


On Tuesday, 1 September 2020 10:46:21 PDT Giuseppe D'Angelo via Development 
wrote:
> Pedantically: if any and all non-const function will invalidate
> iterators, then calling any algorithm that takes an iterator range
> becomes formally impossible (unless one obtains an iterator range in one
> function call, but QVector doesn't have that).

Ok, the wording was incorrect then.

Non-const mutating functions must be assumed to invalidate all iterators. If 
you remove or append or insert an item in the container, the iterators are 
gone.

Non-const non-mutating functions (like begin()) invalidate iterators obtained 
from const functions only. This was the QT_STRICT_ITERATORS usage and remains 
so. Those functions must ensure the reference count is 1 after the call. That 
means a second non-const non-mutating function does not have to detach again. 
Therefore, your requirement that (begin(), end()) is a valid pair is met, 
regardless of the order in which they are called.

This is most visible in functions like find(): if they don't find the item, 
did they detach?

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel DPG Cloud Engineering





More information about the Development mailing list