cxx20_erase_set.h (1273B)
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_SET_H_ 6 #define BASE_CONTAINERS_CXX20_ERASE_SET_H_ 7 8 #include <set> 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 Compare, class Allocator, class Predicate> 24 size_t EraseIf(std::set<Key, Compare, Allocator>& container, Predicate pred) { 25 return internal::IterateAndEraseIf(container, pred); 26 } 27 28 template <class Key, class Compare, class Allocator, class Predicate> 29 size_t EraseIf(std::multiset<Key, Compare, Allocator>& container, 30 Predicate pred) { 31 return internal::IterateAndEraseIf(container, pred); 32 } 33 34 } // namespace base 35 36 #endif // BASE_CONTAINERS_CXX20_ERASE_SET_H_