about summary refs log tree commit diff
path: root/absl/container/btree_set.h
diff options
context:
space:
mode:
Diffstat (limited to 'absl/container/btree_set.h')
-rw-r--r--absl/container/btree_set.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/absl/container/btree_set.h b/absl/container/btree_set.h
index 2a4d0aceb354..127fb940d40e 100644
--- a/absl/container/btree_set.h
+++ b/absl/container/btree_set.h
@@ -360,6 +360,20 @@ void swap(btree_set<K, C, A> &x, btree_set<K, C, A> &y) {
   return x.swap(y);
 }
 
+// absl::erase_if(absl::btree_set<>, Pred)
+//
+// Erases all elements that satisfy the predicate pred from the container.
+template <typename K, typename C, typename A, typename Pred>
+void erase_if(btree_set<K, C, A> &set, Pred pred) {
+  for (auto it = set.begin(); it != set.end();) {
+    if (pred(*it)) {
+      it = set.erase(it);
+    } else {
+      ++it;
+    }
+  }
+}
+
 // absl::btree_multiset<>
 //
 // An `absl::btree_multiset<K>` is an ordered associative container of
@@ -649,6 +663,20 @@ void swap(btree_multiset<K, C, A> &x, btree_multiset<K, C, A> &y) {
   return x.swap(y);
 }
 
+// absl::erase_if(absl::btree_multiset<>, Pred)
+//
+// Erases all elements that satisfy the predicate pred from the container.
+template <typename K, typename C, typename A, typename Pred>
+void erase_if(btree_multiset<K, C, A> &set, Pred pred) {
+  for (auto it = set.begin(); it != set.end();) {
+    if (pred(*it)) {
+      it = set.erase(it);
+    } else {
+      ++it;
+    }
+  }
+}
+
 ABSL_NAMESPACE_END
 }  // namespace absl