diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2015-04-08 19:44:48 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2015-04-20 07:41:44 +0000 |
commit | 5fdc64f5666d094e34e1373e75ae6e50239d9622 (patch) | |
tree | 51a26d00d1d503d4cf8b453c4a4e05de5e0c2051 /src | |
parent | 1b5f29e28a7022f6cde5232eaad2e8f73bc7ffcc (diff) |
Add qHash(QList)
QLists can be compared for equality, so qHash should be overloaded, too.
[ChangeLog][QtCore][QList] Added qHash(QList).
Change-Id: I9ad91811f12479764cc17d87192539612ceb0b4c
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/tools/qlist.cpp | 11 | ||||
-rw-r--r-- | src/corelib/tools/qlist.h | 8 |
2 files changed, 19 insertions, 0 deletions
diff --git a/src/corelib/tools/qlist.cpp b/src/corelib/tools/qlist.cpp index 126147716c..f4901d336e 100644 --- a/src/corelib/tools/qlist.cpp +++ b/src/corelib/tools/qlist.cpp @@ -633,6 +633,17 @@ void **QListData::erase(void **xi) */ /*! + \fn uint qHash(const QList<T> &key, uint seed = 0) + \since 5.6 + \relates QList + + Returns the hash value for \a key, + using \a seed to seed the calculation. + + This function requires qHash() to be overloaded for the value type \c T. +*/ + +/*! \fn int QList::size() const Returns the number of items in the list. diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index 34ebedce3b..85e4570f45 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -38,6 +38,7 @@ #include <QtCore/qiterator.h> #include <QtCore/qrefcount.h> #include <QtCore/qarraydata.h> +#include <QtCore/qhashfunctions.h> #include <iterator> #include <list> @@ -1022,6 +1023,13 @@ Q_DECLARE_SEQUENTIAL_ITERATOR(List) Q_DECLARE_MUTABLE_SEQUENTIAL_ITERATOR(List) template <typename T> +uint qHash(const QList<T> &key, uint seed = 0) + Q_DECL_NOEXCEPT_EXPR(noexcept(qHashRange(key.cbegin(), key.cend(), seed))) +{ + return qHashRange(key.cbegin(), key.cend(), seed); +} + +template <typename T> bool operator<(const QList<T> &lhs, const QList<T> &rhs) Q_DECL_NOEXCEPT_EXPR(noexcept(std::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end()))) |