From b30b3248caff5f3221e2de62a35bc16decb93b6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Wed, 26 Feb 2020 14:53:07 +0100 Subject: [PATCH] QMap: undeprecate QMap::count(Key) For compatibility with std::map Change-Id: Icba536244aadcad97c59dfd4bb22a7fdea881a7b Reviewed-by: Lars Knoll --- src/corelib/tools/qmap.cpp | 8 +------ 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 int QMap::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 int QMap::count() const @@ -2115,11 +2114,6 @@ void QMapDataBase::freeData(QMapDataBase *d) inserted one. */ -/*! \fn template int QMultiMap::count(const Key &key) const - - Returns the number of items associated with key \a key. -*/ - /*! \fn template QList QMultiMap::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 uniqueKeys() const; QT_DEPRECATED_VERSION_X_5_15("Use QMultiMap for maps storing multiple values with the same key.") QList 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(); } @@ -680,6 +680,23 @@ Q_INLINE_TEMPLATE T &QMap::operator[](const Key &akey) return n->value; } +template +Q_INLINE_TEMPLATE int QMap::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 Q_INLINE_TEMPLATE bool QMap::contains(const Key &akey) const { @@ -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::iterator find(const Key &key, const T &value) { @@ -1315,23 +1331,6 @@ Q_INLINE_TEMPLATE int QMultiMap::remove(const Key &key, const T &value) return n; } -template -Q_INLINE_TEMPLATE int QMultiMap::count(const Key &akey) const -{ - QMultiMap::Node *firstNode; - QMultiMap::Node *lastNode; - this->d->nodeRange(akey, &firstNode, &lastNode); - - typename QMap::const_iterator ci_first(firstNode); - const typename QMap::const_iterator ci_last(lastNode); - int cnt = 0; - while (ci_first != ci_last) { - ++cnt; - ++ci_first; - } - return cnt; -} - template Q_INLINE_TEMPLATE int QMultiMap::count(const Key &key, const T &value) const { @@ -1359,12 +1358,6 @@ QList QMap::values(const Key &key) const return static_cast *>(this)->values(key); } -template -int QMap::count(const Key &key) const -{ - return static_cast *>(this)->count(key); -} - template typename QMap::iterator QMap::insertMulti(const Key &key, const T &value) {