From kde-devel Sun Oct 31 12:27:48 2004 From: Esben Mose Hansen Date: Sun, 31 Oct 2004 12:27:48 +0000 To: kde-devel Subject: Re: "Fixed" post-increment operators on iterators Message-Id: <200410311327.48413.kde () mosehansen ! dk> X-MARC-Message: https://marc.info/?l=kde-devel&m=109922619102371 On Sunday 31 October, 2004 12:59, Frederik Schmid wrote: > > QStringList::ConstIterator itEnd = matches.end(); > > for(QStringList::ConstIterator it = matches.begin(); it != itEnd; ++it) > > _keyList->insertItem(*it); [...] > The compiler will (almost certainly) move loop-conditions out ouf the > loop, so no need to add extra lines in this case. I have always wondered about that. Unless the container is const, how can the compiler know that mycontainer->end() always returns the same value? Also, why is it we don't use STL? The above could be written as (untested) std::foreach(matches.begin(), matches.end(), std::bind1st(std::mem_fun(&KeyList::iterator), _keyList)); Or, if QT properly supports the STL (or KDE writes the supporting functors): std::copy(matches.begin(), matches.end(), std::back_inserter(*_keyList)); Those algorithm avoids all these subtle pitsfalls, and the code is (IMHO) much clearer. Just me 0.02€ -- regards, Esben >> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<