cxx20_erase_set.h 1.3 KB

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