[Qt-interest] FW: Iterators and implicitly shared containers
Ben Swerts
benswerts at telenet.be
Sat Dec 18 17:40:31 CET 2010
Sorry about that, Ctrl+Enter is not the key combination you want to use in
Outlook while writing a reply...
> >>however, the *it=2; should recognize that the ref
> count > 1, and
> >>do a detach/deep copy as necessary no??
> >>
> >>Soctt
>
> This is what I would expect,
> but I afraid that you can't achieve it at least with
> current implementation of iterators/containers sharing in Qt.
>
> The way to fix your code is to obtain iterator after assignment.
> Modification below will produce results you expected,
> cause detachment will be done when v1.begin() is called.
>
> If I were you I would try to report the bug. If not
> fixed it will be good at least to have a special warning in
> documentation which identifies possible problem.
Due to your comment, I checked the documentation of QVector and then
implicit sharing. It is actually mentioned there!
"Warning: Do not copy an implicitly shared container (QMap, QVector, etc.)
while you are iterating over it using an non-const STL-style iterator."
Well, I have to do it anyway so thanks to Sean I now know that QVector has a
public detach() function. I wasn't aware that Qt classes do not have all
their public functions documented.
Thanks Sean, Scott and Alex.
Greets,
Ben
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: ATT00059.txt
Url: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20101218/16280864/attachment.txt
More information about the Qt-interest-old
mailing list