[kde-edu]: foreach over containers
Albert Astals Cid
aacid at kde.org
Sun Jan 14 18:25:46 CET 2007
Hi, this is just a mail to explain how foreach works.
when you do
foreach( X, container<T> )
the thing that is returned to be put on X is a element of type "const T".
So X can either be
T
const T
const &T
the best of the three is const &T as it avoids calling the copy constructor.
If you look closely, you sill see that the only of the three that returns the
real value in the container is const &T, that means you can not modify the
container elements using a foreach, you have to use iteratots for modifying
the container contents.
And we have some code that tries to do that on
libkdeedu/kdeeducore/keduvocdocument.cpp
for example
foreach( KEduVocExpression exp, m_vocabulary )
exp.removeTranslation(index);
is a no-op
Peter, can you fix it?
Albert
P.S: I'm sending a simple example code for the non believers ;-)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.cxx
Type: text/x-c++src
Size: 272 bytes
Desc: not available
Url : http://mail.kde.org/pipermail/kde-edu/attachments/20070114/d1e6df67/attachment.bin
More information about the kde-edu
mailing list