Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any ideas why QHash and QMap return const T instead of const T&?

Unlike std::map and std::hash_map, corresponding versions in Qt do not bother to return a reference. Isn't it quite inefficient, if I build a hash for quite bulky class?

EDIT

especially since there is a separate method value(), which could then return it by value.

like image 310
MadH Avatar asked Jul 14 '09 09:07

MadH


1 Answers

The documentation for QMap and QHash specifically say to avoid operator[] for lookup due to the reason Martin B stated.

If you want a const reference, use const_iterator find ( const Key & key ) const where you can then use any of:

const Key & key () const
const T & value () const
const T & operator* () const
const T * operator-> () const
like image 97
Adam W Avatar answered Oct 27 '22 01:10

Adam W