diff options
author | Mårten Nordheim <marten.nordheim@qt.io> | 2020-02-26 14:53:07 +0100 |
---|---|---|
committer | Mårten Nordheim <marten.nordheim@qt.io> | 2020-03-03 11:41:42 +0100 |
commit | b30b3248caff5f3221e2de62a35bc16decb93b6f (patch) | |
tree | 248b7295877ba5e4f72cbf79da8305103f30899e /src | |
parent | bac89e2f49c1b7dda063aad8635a5d3cffad2c36 (diff) | |
download | qtbase-b30b3248caff5f3221e2de62a35bc16decb93b6f.tar.gz |
QMap: undeprecate QMap::count(Key)
For compatibility with std::map
Change-Id: Icba536244aadcad97c59dfd4bb22a7fdea881a7b
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/tools/qmap.cpp | 8 | ||||
-rw-r--r-- | src/corelib/tools/qmap.h | 43 |
2 files changed, 19 insertions, 32 deletions
diff --git a/src/corelib/tools/qmap.cpp b/src/corelib/tools/qmap.cpp index 6d2b8f7a3e..25ea5f25d7 100644 --- a/src/corelib/tools/qmap.cpp +++ b/src/corelib/tools/qmap.cpp @@ -814,11 +814,10 @@ void QMapDataBase::freeData(QMapDataBase *d) */ /*! \fn template <class Key, class T> int QMap<Key, T>::count(const Key &key) const - \obsolete Returns the number of items associated with key \a key. - \sa QMultiMap::count() + \sa contains(), QMultiMap::count() */ /*! \fn template <class Key, class T> int QMap<Key, T>::count() const @@ -2115,11 +2114,6 @@ void QMapDataBase::freeData(QMapDataBase *d) inserted one. */ -/*! \fn template <class Key, class T> int QMultiMap<Key, T>::count(const Key &key) const - - Returns the number of items associated with key \a key. -*/ - /*! \fn template <class Key, class T> QList<Key> QMultiMap<Key, T>::uniqueKeys() const \since 4.2 diff --git a/src/corelib/tools/qmap.h b/src/corelib/tools/qmap.h index 21628032c8..0c69d13295 100644 --- a/src/corelib/tools/qmap.h +++ b/src/corelib/tools/qmap.h @@ -386,8 +386,8 @@ public: #if QT_DEPRECATED_SINCE(5, 15) QT_DEPRECATED_VERSION_X_5_15("Use QMultiMap for maps storing multiple values with the same key.") QList<Key> uniqueKeys() const; QT_DEPRECATED_VERSION_X_5_15("Use QMultiMap for maps storing multiple values with the same key.") QList<T> values(const Key &key) const; - QT_DEPRECATED_VERSION_X_5_15("Use QMultiMap for maps storing multiple values with the same key.") int count(const Key &key) const; #endif + int count(const Key &key) const; inline const Key &firstKey() const { Q_ASSERT(!isEmpty()); return constBegin().key(); } @@ -681,6 +681,23 @@ Q_INLINE_TEMPLATE T &QMap<Key, T>::operator[](const Key &akey) } template <class Key, class T> +Q_INLINE_TEMPLATE int QMap<Key, T>::count(const Key &akey) const +{ + Node *firstNode; + Node *lastNode; + d->nodeRange(akey, &firstNode, &lastNode); + + const_iterator ci_first(firstNode); + const const_iterator ci_last(lastNode); + int cnt = 0; + while (ci_first != ci_last) { + ++cnt; + ++ci_first; + } + return cnt; +} + +template <class Key, class T> Q_INLINE_TEMPLATE bool QMap<Key, T>::contains(const Key &akey) const { return d->findNode(akey) != nullptr; @@ -1142,7 +1159,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; typename QMap<Key, T>::iterator find(const Key &key, const T &value) { @@ -1316,23 +1332,6 @@ Q_INLINE_TEMPLATE int QMultiMap<Key, T>::remove(const Key &key, const T &value) } template <class Key, class T> -Q_INLINE_TEMPLATE int QMultiMap<Key, T>::count(const Key &akey) const -{ - QMultiMap::Node *firstNode; - QMultiMap::Node *lastNode; - this->d->nodeRange(akey, &firstNode, &lastNode); - - typename QMap<Key, T>::const_iterator ci_first(firstNode); - const typename QMap<Key, T>::const_iterator ci_last(lastNode); - int cnt = 0; - while (ci_first != ci_last) { - ++cnt; - ++ci_first; - } - return cnt; -} - -template <class Key, class T> Q_INLINE_TEMPLATE int QMultiMap<Key, T>::count(const Key &key, const T &value) const { int n = 0; @@ -1360,12 +1359,6 @@ QList<T> QMap<Key, T>::values(const Key &key) const } template<class Key, class T> -int QMap<Key, T>::count(const Key &key) const -{ - return static_cast<const QMultiMap<Key, T> *>(this)->count(key); -} - -template<class Key, class T> typename QMap<Key, T>::iterator QMap<Key, T>::insertMulti(const Key &key, const T &value) { return static_cast<QMultiMap<Key, T> *>(this)->insert(key, value); |