diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2016-11-01 08:40:20 +0000 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2016-12-12 11:15:22 +0000 |
commit | 1da70af724e16caa6ce175630f13434fcded512b (patch) | |
tree | 9c082a45d0010395ff81fc8bb52e98da2f211d38 /src/corelib/tools/qmap.cpp | |
parent | 888b3f504529274ffb799bcbe88023c79e13e451 (diff) |
QMap: use std::less for defining an order between pointers
Reinterpret_cast()ing a pointer to a suitably sized integer is not guaranteed
to always give the same result for the same pointer (!). Therefore the
resulting integers are not comparable in a meaningful way. std::less is
supposed to be used to compare arbitrary pointers, so use it.
(Hopefully and reasonably, under the hood std::less does exactly what we
were doing, so this isn't BiC.)
Change-Id: I9960b3d6e35657fe7a25b842054f5d338280e850
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qmap.cpp')
-rw-r--r-- | src/corelib/tools/qmap.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/corelib/tools/qmap.cpp b/src/corelib/tools/qmap.cpp index 406eb31923..94ed47f898 100644 --- a/src/corelib/tools/qmap.cpp +++ b/src/corelib/tools/qmap.cpp @@ -399,7 +399,9 @@ void QMapDataBase::freeData(QMapDataBase *d) With QMap, the items are always sorted by key. \li The key type of a QHash must provide operator==() and a global qHash(Key) function. The key type of a QMap must provide - operator<() specifying a total order. + operator<() specifying a total order. Since Qt 5.8.1 it is also safe + to use a pointer type as key, even if the underlying operator<() + does not provide a total order. \endlist Here's an example QMap with QString keys and \c int values: |