unordered_map 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // <unordered_map> -*- C++ -*-
  2. // Copyright (C) 2007-2022 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // Under Section 7 of GPL version 3, you are granted additional
  14. // permissions described in the GCC Runtime Library Exception, version
  15. // 3.1, as published by the Free Software Foundation.
  16. // You should have received a copy of the GNU General Public License and
  17. // a copy of the GCC Runtime Library Exception along with this program;
  18. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. // <http://www.gnu.org/licenses/>.
  20. /** @file include/unordered_map
  21. * This is a Standard C++ Library header.
  22. */
  23. #ifndef _GLIBCXX_UNORDERED_MAP
  24. #define _GLIBCXX_UNORDERED_MAP 1
  25. #pragma GCC system_header
  26. #if __cplusplus < 201103L
  27. # include <bits/c++0x_warning.h>
  28. #else
  29. #include <type_traits>
  30. #include <initializer_list>
  31. #include <bits/allocator.h>
  32. #include <ext/alloc_traits.h>
  33. #include <ext/aligned_buffer.h>
  34. #include <bits/stl_pair.h>
  35. #include <bits/stl_function.h> // equal_to, _Identity, _Select1st
  36. #include <bits/functional_hash.h>
  37. #include <bits/hashtable.h>
  38. #include <bits/unordered_map.h>
  39. #include <bits/range_access.h>
  40. #include <bits/erase_if.h>
  41. #ifdef _GLIBCXX_DEBUG
  42. # include <debug/unordered_map>
  43. #endif
  44. #if __cplusplus >= 201703L
  45. namespace std _GLIBCXX_VISIBILITY(default)
  46. {
  47. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  48. namespace pmr
  49. {
  50. template<typename _Tp> class polymorphic_allocator;
  51. template<typename _Key, typename _Tp, typename _Hash = std::hash<_Key>,
  52. typename _Pred = std::equal_to<_Key>>
  53. using unordered_map
  54. = std::unordered_map<_Key, _Tp, _Hash, _Pred,
  55. polymorphic_allocator<pair<const _Key, _Tp>>>;
  56. template<typename _Key, typename _Tp, typename _Hash = std::hash<_Key>,
  57. typename _Pred = std::equal_to<_Key>>
  58. using unordered_multimap
  59. = std::unordered_multimap<_Key, _Tp, _Hash, _Pred,
  60. polymorphic_allocator<pair<const _Key, _Tp>>>;
  61. } // namespace pmr
  62. _GLIBCXX_END_NAMESPACE_VERSION
  63. } // namespace std
  64. #endif // C++17
  65. #if __cplusplus > 201703L
  66. namespace std _GLIBCXX_VISIBILITY(default)
  67. {
  68. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  69. template<typename _Key, typename _Tp, typename _Hash, typename _CPred,
  70. typename _Alloc, typename _Predicate>
  71. inline typename unordered_map<_Key, _Tp, _Hash, _CPred, _Alloc>::size_type
  72. erase_if(unordered_map<_Key, _Tp, _Hash, _CPred, _Alloc>& __cont,
  73. _Predicate __pred)
  74. {
  75. const _GLIBCXX_STD_C::unordered_map<_Key, _Tp, _Hash, _CPred, _Alloc>&
  76. __ucont = __cont;
  77. return __detail::__erase_nodes_if(__cont, __ucont, __pred);
  78. }
  79. template<typename _Key, typename _Tp, typename _Hash, typename _CPred,
  80. typename _Alloc, typename _Predicate>
  81. inline typename unordered_multimap<_Key, _Tp, _Hash, _CPred, _Alloc>::
  82. size_type
  83. erase_if(unordered_multimap<_Key, _Tp, _Hash, _CPred, _Alloc>& __cont,
  84. _Predicate __pred)
  85. {
  86. const _GLIBCXX_STD_C::unordered_multimap<_Key, _Tp, _Hash, _CPred, _Alloc>&
  87. __ucont = __cont;
  88. return __detail::__erase_nodes_if(__cont, __ucont, __pred);
  89. }
  90. _GLIBCXX_END_NAMESPACE_VERSION
  91. } // namespace std
  92. #endif // C++20
  93. #endif // C++11
  94. #endif // _GLIBCXX_UNORDERED_MAP