[Interest] Q_FOREACH creating copy , was (no subject)
André Somers
andre at familiesomers.nl
Tue Jun 30 14:08:41 CEST 2015
Koehne Kai schreef op 30-6-2015 om 14:04:
>
> There's nothing bad with using STL iterators with Qt containers, and I didn't intend to say anything like this. In fact, if you really want to have the best performance and don't mind the verbosity,
>
> for (auto iter = myQtContainer.cbegin(); iter != myQtContainer.cend(); ++iter)
>
> is guaranteed to have the least overhead.
>
> My comment was just about range-based for, that is
>
> for (auto value, myQtContainer) {
> }
>
> And that this might be more expensive than expected, because it calls begin(), which might detach. That's all.
>
>
Just a note: AFAIK, you can also prevent the detach by iterating over a
const ref to the container instead of the actual one. However, that also
is more work to write, of course.
André
More information about the Interest
mailing list