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>
This commit is contained in:
parent
1b5f29e28a
commit
5fdc64f566
@ -632,6 +632,17 @@ void **QListData::erase(void **xi)
|
||||
of \c operator<().
|
||||
*/
|
||||
|
||||
/*!
|
||||
\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
|
||||
|
||||
|
@ -38,6 +38,7 @@
|
||||
#include <QtCore/qiterator.h>
|
||||
#include <QtCore/qrefcount.h>
|
||||
#include <QtCore/qarraydata.h>
|
||||
#include <QtCore/qhashfunctions.h>
|
||||
|
||||
#include <iterator>
|
||||
#include <list>
|
||||
@ -1021,6 +1022,13 @@ inline int QList<T>::count_impl(const T &t, QListData::ArrayCompatibleLayout) co
|
||||
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(),
|
||||
|
@ -399,6 +399,9 @@ private slots:
|
||||
void eraseValidIteratorsOnSharedList() const;
|
||||
void insertWithValidIteratorsOnSharedList() const;
|
||||
|
||||
void qhashOptimal() const { qhash<Optimal>(); }
|
||||
void qhashMovable() const { qhash<Movable>(); }
|
||||
void qhashComplex() const { qhash<Complex>(); }
|
||||
void reserve() const;
|
||||
private:
|
||||
template<typename T> void length() const;
|
||||
@ -415,6 +418,7 @@ private:
|
||||
template<typename T> void endsWith() const;
|
||||
template<typename T> void lastIndexOf() const;
|
||||
template<typename T> void move() const;
|
||||
template<typename T> void qhash() const;
|
||||
template<typename T> void removeAll() const;
|
||||
template<typename T> void removeAt() const;
|
||||
template<typename T> void removeOne() const;
|
||||
@ -1908,6 +1912,16 @@ void tst_QList::insertWithValidIteratorsOnSharedList() const
|
||||
QCOMPARE(a.at(1), 15);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void tst_QList::qhash() const
|
||||
{
|
||||
QList<T> l1, l2;
|
||||
QCOMPARE(qHash(l1), qHash(l2));
|
||||
l1 << T_BAR;
|
||||
l2 << T_BAR;
|
||||
QCOMPARE(qHash(l1), qHash(l2));
|
||||
}
|
||||
|
||||
void tst_QList::reserve() const
|
||||
{
|
||||
// Note:
|
||||
|
Loading…
Reference in New Issue
Block a user