summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qmap.h
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2020-10-16 20:52:48 +0200
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2020-12-02 10:35:14 +0100
commite12e2b43b7e6b42d17556eb8ed392c31589a0b4a (patch)
tree1575582d6d78bd66914c2499daba0df8c997ed48 /src/corelib/tools/qmap.h
parent9341f2e3d0a877b50ba851ff22b0d6ce192faf84 (diff)
Associative containers: add erase_if
Use a trick similar to the one we use for their ranged constructors: support predicates that either take a container's iterator, or that take a std::pair (for STL compatibility). [ChangeLog][QtCore][QMap] Added removeIf() and erase_if(). [ChangeLog][QtCore][QMultiMap] Added removeIf() and erase_if(). [ChangeLog][QtCore][QHash] Added removeIf() and erase_if(). [ChangeLog][QtCore][QMultiHash] Added removeIf() and erase_if(). Change-Id: Ie40aadf6217d7a4126a626c390d530812ebcf020 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qmap.h')
-rw-r--r--src/corelib/tools/qmap.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/corelib/tools/qmap.h b/src/corelib/tools/qmap.h
index a426a202e1..b64989eadd 100644
--- a/src/corelib/tools/qmap.h
+++ b/src/corelib/tools/qmap.h
@@ -343,6 +343,12 @@ public:
return result;
}
+ template <typename Predicate>
+ size_type removeIf(Predicate pred)
+ {
+ return QtPrivate::associative_erase_if(*this, pred);
+ }
+
T take(const Key &key)
{
if (!d)
@@ -742,6 +748,12 @@ public:
Q_DECLARE_ASSOCIATIVE_ITERATOR(Map)
Q_DECLARE_MUTABLE_ASSOCIATIVE_ITERATOR(Map)
+template <typename Key, typename T, typename Predicate>
+qsizetype erase_if(QMap<Key, T> &map, Predicate pred)
+{
+ return QtPrivate::associative_erase_if(map, pred);
+}
+
//
// QMultiMap
//
@@ -938,6 +950,12 @@ public:
return result;
}
+ template <typename Predicate>
+ size_type removeIf(Predicate pred)
+ {
+ return QtPrivate::associative_erase_if(*this, pred);
+ }
+
T take(const Key &key)
{
if (!d)
@@ -1441,6 +1459,12 @@ QMultiMap<Key, T> operator+=(QMultiMap<Key, T> &lhs, const QMultiMap<Key, T> &rh
return lhs.unite(rhs);
}
+template <typename Key, typename T, typename Predicate>
+qsizetype erase_if(QMultiMap<Key, T> &map, Predicate pred)
+{
+ return QtPrivate::associative_erase_if(map, pred);
+}
+
QT_END_NAMESPACE
#endif // QMAP_H