cxx20_erase_unordered_map.h (1506B)
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_UNORDERED_MAP_H_ 6 #define BASE_CONTAINERS_CXX20_ERASE_UNORDERED_MAP_H_ 7 8 #include <unordered_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, 24 class T, 25 class Hash, 26 class KeyEqual, 27 class Allocator, 28 class Predicate> 29 size_t EraseIf(std::unordered_map<Key, T, Hash, KeyEqual, Allocator>& container, 30 Predicate pred) { 31 return internal::IterateAndEraseIf(container, pred); 32 } 33 34 template <class Key, 35 class T, 36 class Hash, 37 class KeyEqual, 38 class Allocator, 39 class Predicate> 40 size_t EraseIf( 41 std::unordered_multimap<Key, T, Hash, KeyEqual, Allocator>& container, 42 Predicate pred) { 43 return internal::IterateAndEraseIf(container, pred); 44 } 45 46 } // namespace base 47 48 #endif // BASE_CONTAINERS_CXX20_ERASE_UNORDERED_MAP_H_