tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

cxx20_erase_unordered_set.h (1462B)


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