QMap: undeprecate QMap::count(Key)

For compatibility with std::map

Change-Id: Icba536244aadcad97c59dfd4bb22a7fdea881a7b
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
Mårten Nordheim 2020-02-26 14:53:07 +01:00
parent bac89e2f49
commit b30b3248ca
2 changed files with 19 additions and 32 deletions

View File

@ -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

View File

@ -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(); }
@ -680,6 +680,23 @@ Q_INLINE_TEMPLATE T &QMap<Key, T>::operator[](const Key &akey)
return n->value;
}
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
{
@ -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) {
@ -1315,23 +1331,6 @@ Q_INLINE_TEMPLATE int QMultiMap<Key, T>::remove(const Key &key, const T &value)
return n;
}
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
{
@ -1359,12 +1358,6 @@ QList<T> QMap<Key, T>::values(const Key &key) const
return static_cast<const QMultiMap<Key, T> *>(this)->values(key);
}
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)
{