diff --git a/doc/unordered/unordered_map.adoc b/doc/unordered/unordered_map.adoc index e8737402..9610d853 100644 --- a/doc/unordered/unordered_map.adoc +++ b/doc/unordered/unordered_map.adoc @@ -198,6 +198,10 @@ template void xref:#unordered_map_swap_2[swap](unordered_map& x, unordered_map& y) noexcept(noexcept(x.swap(y))); + +template + typename unordered_map::size_type + xref:#unordered_map_erase_if[erase_if](unordered_map& c, Predicate pred); ----- --- @@ -1424,4 +1428,31 @@ Effects:;; `x.swap(y)` Throws:;; Doesn't throw an exception unless it is thrown by the copy constructor or copy assignment operator of `key_equal` or `hasher`. Notes:;; The exception specifications aren't quite the same as the C++11 standard, as the equality predicate and hash function are swapped using their copy constructors. +--- +=== erase_if +```c++ +template + typename unordered_map::size_type + erase_if(unordered_map& c, Predicate pred); +``` + +Traverses the container `c` and removes all elements for which the supplied predicate returns `true`. + +[horizontal] +Returns:;; The number of erased elements. +Notes:;; Equivalent to: + ++ +```c++ +auto original_size = c.size(); +for (auto i = c.begin(), last = c.end(); i != last; ) { + if (pred(*i)) { + i = c.erase(i); + } else { + ++i; + } +} +return original_size - c.size(); +``` + +--- diff --git a/doc/unordered/unordered_multimap.adoc b/doc/unordered/unordered_multimap.adoc index 8eb8fb30..bd6745f9 100644 --- a/doc/unordered/unordered_multimap.adoc +++ b/doc/unordered/unordered_multimap.adoc @@ -193,6 +193,11 @@ template void xref:#unordered_multimap_swap_2[swap](unordered_multimap& x, unordered_multimap& y) noexcept(noexcept(x.swap(y))); + +template + typename unordered_multimap::size_type + xref:#unordered_multimap_erase_if[erase_if](unordered_multimap& c, Predicate pred); + ----- --- @@ -1368,4 +1373,31 @@ Effects:;; `x.swap(y)` Throws:;; Doesn't throw an exception unless it is thrown by the copy constructor or copy assignment operator of `key_equal` or `hasher`. Notes:;; The exception specifications aren't quite the same as the C++11 standard, as the equality predicate and hash function are swapped using their copy constructors. +--- +=== erase_if +```c++ +template + typename unordered_multimap::size_type + erase_if(unordered_multimap& c, Predicate pred); +``` + +Traverses the container `c` and removes all elements for which the supplied predicate returns `true`. + +[horizontal] +Returns:;; The number of erased elements. +Notes:;; Equivalent to: + ++ +```c++ +auto original_size = c.size(); +for (auto i = c.begin(), last = c.end(); i != last; ) { + if (pred(*i)) { + i = c.erase(i); + } else { + ++i; + } +} +return original_size - c.size(); +``` + +--- diff --git a/doc/unordered/unordered_multiset.adoc b/doc/unordered/unordered_multiset.adoc index 122a1b27..d900799d 100644 --- a/doc/unordered/unordered_multiset.adoc +++ b/doc/unordered/unordered_multiset.adoc @@ -187,6 +187,10 @@ template void xref:#unordered_multiset_swap_2[swap](unordered_multiset& x, unordered_multiset& y) noexcept(noexcept(x.swap(y))); + +template + typename unordered_multiset::size_type + xref:#unordered_multiset_erase_if[erase_if](unordered_multiset& c, Predicate pred); ----- --- @@ -1326,4 +1330,31 @@ Effects:;; `x.swap(y)` Throws:;; Doesn't throw an exception unless it is thrown by the copy constructor or copy assignment operator of `key_equal` or `hasher`. Notes:;; The exception specifications aren't quite the same as the C++11 standard, as the equality predicate and hash function are swapped using their copy constructors. +--- +=== erase_if +```c++ +template + typename unordered_multiset::size_type + erase_if(unordered_multiset& c, Predicate pred); +``` + +Traverses the container `c` and removes all elements for which the supplied predicate returns `true`. + +[horizontal] +Returns:;; The number of erased elements. +Notes:;; Equivalent to: + ++ +```c++ +auto original_size = c.size(); +for (auto i = c.begin(), last = c.end(); i != last; ) { + if (pred(*i)) { + i = c.erase(i); + } else { + ++i; + } +} +return original_size - c.size(); +``` + +--- diff --git a/doc/unordered/unordered_set.adoc b/doc/unordered/unordered_set.adoc index e976b97a..1987b317 100644 --- a/doc/unordered/unordered_set.adoc +++ b/doc/unordered/unordered_set.adoc @@ -188,6 +188,10 @@ template void xref:#unordered_set_swap_2[swap](unordered_set& x, unordered_set& y) noexcept(noexcept(x.swap(y))); + +template + typename unordered_set::size_type + xref:#unordered_set_erase_if[erase_if](unordered_set& c, Predicate pred); ----- --- @@ -1349,3 +1353,30 @@ Throws:;; Doesn't throw an exception unless it is thrown by the copy constructor Notes:;; The exception specifications aren't quite the same as the C++11 standard, as the equality predicate and hash function are swapped using their copy constructors. --- + +=== erase_if +```c++ +template + typename unordered_set::size_type + erase_if(unordered_set& c, Predicate pred); +``` + +Traverses the container `c` and removes all elements for which the supplied predicate returns `true`. + +[horizontal] +Returns:;; The number of erased elements. +Notes:;; Equivalent to: + ++ +```c++ +auto original_size = c.size(); +for (auto i = c.begin(), last = c.end(); i != last; ) { + if (pred(*i)) { + i = c.erase(i); + } else { + ++i; + } +} +return original_size - c.size(); +``` + +---