vectors vs. lists
Simon Hausmann
hausmann at kde.org
Thu Feb 19 21:11:42 GMT 2004
On Thursday 19 February 2004 10:46, Marc Mutz wrote:
[...]
> Tha janitorial job would involve finding wrong uses of QValueList and
> fixing them to use QValueVector.
When converting to from QValueList to QValueVector keep in mind that that
QValueList's iterators have special properties:
1) Iterators remain valid as long as the item they point to exists. This is
not the case with QValueVector, so after an insertion for example all
existing iterators are invalid (in some cases they may remain valid, but it's
nothing good to rely on) .
2) QValueList's linked list forms a circle, so if your iterator equals
list.end() and you advance it then you are at the beginning again. Reverse
applies of course to begin() . This is not the case with QValueVector's
iterators.
Both are things that one can easily rely on by accident (think of loops that
traverse a valuelist from the end to the beginning for example) . So just
don't blindly replace QValueList with QValueVector and watch your code
compile.
My humble opinion: Don't get scared. I don't think most of the time it's
thaaat horrible. I guess it makes a difference in the total sum of it, but
that part will get solved with much less effort with Qt 4.
Simon
More information about the kde-core-devel
mailing list