diff options
author | Mårten Nordheim <marten.nordheim@qt.io> | 2020-02-25 16:41:13 +0100 |
---|---|---|
committer | Mårten Nordheim <marten.nordheim@qt.io> | 2020-03-03 11:41:34 +0100 |
commit | f4fca8697ffaf64a2e919bbbb96fbd2639c7ac60 (patch) | |
tree | 3f41a763b0b80d3a4c0b2e2afa408b71bc23acc3 /src/corelib | |
parent | c3fc9a24d8695447416b0eb40590fabea7287444 (diff) |
Undeprecate QHash::count(Key)
For compatibility with std::unordered_map. Spotted in the API review.
Change-Id: Ic34600d55baebcbbf115c1090cd555984037c44c
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/tools/qhash.cpp | 8 | ||||
-rw-r--r-- | src/corelib/tools/qhash.h | 35 |
2 files changed, 14 insertions, 29 deletions
diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp index 15f731a603..7ebc374d9f 100644 --- a/src/corelib/tools/qhash.cpp +++ b/src/corelib/tools/qhash.cpp @@ -1574,7 +1574,6 @@ uint qHash(long double key, uint seed) noexcept */ /*! \fn template <class Key, class T> int QHash<Key, T>::count(const Key &key) const - \obsolete Returns the number of items associated with the \a key. @@ -2693,13 +2692,6 @@ uint qHash(long double key, uint seed) noexcept \sa QHash::remove() */ -/*! \fn template <class Key, class T> int QMultiHash<Key, T>::count(const Key &key) const - - Returns the number of items associated with the \a key. - - \sa contains(), insert() -*/ - /*! \fn template <class Key, class T> int QMultiHash<Key, T>::count(const Key &key, const T &value) const \since 4.3 diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index 9144405501..06313d6c79 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -314,8 +314,8 @@ public: #if QT_DEPRECATED_SINCE(5, 15) QT_DEPRECATED_X("Use QMultiHash for hashes storing multiple values with the same key.") QList<Key> uniqueKeys() const; QT_DEPRECATED_X("Use QMultiHash for hashes storing multiple values with the same key.") QList<T> values(const Key &key) const; - QT_DEPRECATED_X("Use QMultiHash for hashes storing multiple values with the same key.") int count(const Key &key) const; #endif + int count(const Key &key) const; class const_iterator; @@ -730,6 +730,19 @@ Q_OUTOFLINE_TEMPLATE QList<T> QHash<Key, T>::values() const } template <class Key, class T> +Q_OUTOFLINE_TEMPLATE int QHash<Key, T>::count(const Key &akey) const +{ + int cnt = 0; + Node *node = *findNode(akey); + if (node != e) { + do { + ++cnt; + } while ((node = node->next) != e && node->key == akey); + } + return cnt; +} + +template <class Key, class T> Q_INLINE_TEMPLATE const T QHash<Key, T>::operator[](const Key &akey) const { return value(akey); @@ -1072,7 +1085,6 @@ public: int remove(const Key &key, const T &value); - int count(const Key &key) const; int count(const Key &key, const T &value) const; QList<Key> uniqueKeys() const; @@ -1226,12 +1238,6 @@ Q_OUTOFLINE_TEMPLATE QList<T> QHash<Key, T>::values(const Key &akey) const } template <class Key, class T> -Q_OUTOFLINE_TEMPLATE int QHash<Key, T>::count(const Key &akey) const -{ - return static_cast<const QMultiHash<Key, T> *>(this)->count(akey); -} - -template <class Key, class T> Q_OUTOFLINE_TEMPLATE QList<Key> QHash<Key, T>::uniqueKeys() const { return static_cast<const QMultiHash<Key, T> *>(this)->uniqueKeys(); @@ -1251,19 +1257,6 @@ Q_OUTOFLINE_TEMPLATE QList<T> QMultiHash<Key, T>::values(const Key &akey) const return res; } -template <class Key, class T> -Q_OUTOFLINE_TEMPLATE int QMultiHash<Key, T>::count(const Key &akey) const -{ - int cnt = 0; - Node *node = *findNode(akey); - if (node != this->e) { - do { - ++cnt; - } while ((node = node->next) != this->e && node->key == akey); - } - return cnt; -} - #if !defined(QT_NO_JAVA_STYLE_ITERATORS) template <class Key, class T> class QHashIterator |