[Interest] Q_FOREACH creating copy , was (no subject)

Alejandro Exojo suy at badopi.org
Sun Jun 28 02:44:00 CEST 2015


El Saturday 27 June 2015, Prav escribió:
> > I think the advice should be to use foreach with Qt containers, range
> > based for for stl one's. I uploaded
> > https://codereview.qt-project.org/#/c/115358/1
> > to make this part of the documentation.
> 
> Thanks!  By  could  you  explain  more  or get link to this detachment
> issue?

http://doc.qt.io/qt-5/implicit-sharing.html

When a container calls detach(), it means it is no longer attached to the 
container it was copied from (if it was copied), so, to be truly independent, 
it needs to copy the data from the original container. This is not done in the 
copy constructor for the "copy on write" feature, or "copy only when really 
needed" as I prefer to explain it.

Implicit sharing is well explained on that link, but the name "detach" is a 
bit of an inside Qt jargon thing, since detach() is internal API. Somebody who 
used QSharedDataPointer might be familiar too, since it has the same name for 
the same purpose.

I've mentioned in the review request just in case.

-- 
Alex (a.k.a. suy) | GPG ID 0x0B8B0BC2
http://barnacity.net/ | http://disperso.net



More information about the Interest mailing list