KDE/kdelibs/kdecore

David Faure faure at kde.org
Tue Jul 8 09:05:06 BST 2008


On Tuesday 08 July 2008, Andreas Pakulat wrote:
> On 07.07.08 23:19:59, Thiago Macieira wrote:
> > Andreas Pakulat wrote:
> > >I'm not sure why the const_this is needed here anyway, shouldn't a
> > > simple const_iterator and ::constEnd() be sufficient too?
> > 
> > It's needed because of the missing constFind() function. There are two 
> > overloads to find(): one non-const returning an iterator and a const 
> > returning a const_iterator. The only way to select the const version (and 
> > hence avoid detaching) is to have a const container.
> 
> aah, I thought the compiler was clever enough to use the const-version
> when I'm doing
> 
> QHash<Foo,Bar>::const_iterator it = somemap.find();
> 
> Due to the needed const-type on the left hand side.

No, because the RHS is evaluated first, and then that iterator can be converted to a const_iterator.
This is also the reason why constBegin/constEnd exist in the first place.

-- 
David Faure, faure at kde.org, sponsored by Trolltech to work on KDE,
Konqueror (http://www.konqueror.org), and KOffice (http://www.koffice.org).




More information about the kde-core-devel mailing list