1 // Copyright 2021 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef BASE_CONTAINERS_CXX20_ERASE_MAP_H_
6 #define BASE_CONTAINERS_CXX20_ERASE_MAP_H_
7
8 #include <map>
9
10 #include "base/containers/cxx20_erase_internal.h"
11
12 namespace base {
13
14 // EraseIf is based on C++20's uniform container erasure API:
15 // - https://eel.is/c++draft/libraryindex#:erase
16 // - https://eel.is/c++draft/libraryindex#:erase_if
17 // They provide a generic way to erase elements from a container.
18 // The functions here implement these for the standard containers until those
19 // functions are available in the C++ standard.
20 // Note: there is no std::erase for standard associative containers so we don't
21 // have it either.
22
23 template <class Key, class T, class Compare, class Allocator, class Predicate>
EraseIf(std::map<Key,T,Compare,Allocator> & container,Predicate pred)24 size_t EraseIf(std::map<Key, T, Compare, Allocator>& container,
25 Predicate pred) {
26 return internal::IterateAndEraseIf(container, pred);
27 }
28
29 } // namespace base
30
31 #endif // BASE_CONTAINERS_CXX20_ERASE_MAP_H_
32