Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===-------------------------- unordered_map -----------------------------===// |
| 3 | // |
Chandler Carruth | 57b08b0 | 2019-01-19 10:56:40 | [diff] [blame] | 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | // See https://llvm.org/LICENSE.txt for license information. |
| 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP_UNORDERED_MAP |
| 11 | #define _LIBCPP_UNORDERED_MAP |
| 12 | |
| 13 | /* |
| 14 | |
| 15 | unordered_map synopsis |
| 16 | |
| 17 | #include <initializer_list> |
| 18 | |
| 19 | namespace std |
| 20 | { |
| 21 | |
| 22 | template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>, |
| 23 | class Alloc = allocator<pair<const Key, T>>> |
| 24 | class unordered_map |
| 25 | { |
| 26 | public: |
| 27 | // types |
| 28 | typedef Key key_type; |
| 29 | typedef T mapped_type; |
| 30 | typedef Hash hasher; |
| 31 | typedef Pred key_equal; |
| 32 | typedef Alloc allocator_type; |
| 33 | typedef pair<const key_type, mapped_type> value_type; |
| 34 | typedef value_type& reference; |
| 35 | typedef const value_type& const_reference; |
| 36 | typedef typename allocator_traits<allocator_type>::pointer pointer; |
| 37 | typedef typename allocator_traits<allocator_type>::const_pointer const_pointer; |
| 38 | typedef typename allocator_traits<allocator_type>::size_type size_type; |
| 39 | typedef typename allocator_traits<allocator_type>::difference_type difference_type; |
| 40 | |
| 41 | typedef /unspecified/ iterator; |
| 42 | typedef /unspecified/ const_iterator; |
| 43 | typedef /unspecified/ local_iterator; |
| 44 | typedef /unspecified/ const_local_iterator; |
| 45 | |
Erik Pilkington | b0386a5 | 2018-08-01 01:33:38 | [diff] [blame] | 46 | typedef unspecified node_type; // C++17 |
| 47 | typedef INSERT_RETURN_TYPE<iterator, node_type> insert_return_type; // C++17 |
| 48 | |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 49 | unordered_map() |
| 50 | noexcept( |
| 51 | is_nothrow_default_constructible<hasher>::value && |
| 52 | is_nothrow_default_constructible<key_equal>::value && |
| 53 | is_nothrow_default_constructible<allocator_type>::value); |
| 54 | explicit unordered_map(size_type n, const hasher& hf = hasher(), |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 55 | const key_equal& eql = key_equal(), |
| 56 | const allocator_type& a = allocator_type()); |
| 57 | template <class InputIterator> |
| 58 | unordered_map(InputIterator f, InputIterator l, |
| 59 | size_type n = 0, const hasher& hf = hasher(), |
| 60 | const key_equal& eql = key_equal(), |
| 61 | const allocator_type& a = allocator_type()); |
| 62 | explicit unordered_map(const allocator_type&); |
| 63 | unordered_map(const unordered_map&); |
| 64 | unordered_map(const unordered_map&, const Allocator&); |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 65 | unordered_map(unordered_map&&) |
| 66 | noexcept( |
| 67 | is_nothrow_move_constructible<hasher>::value && |
| 68 | is_nothrow_move_constructible<key_equal>::value && |
| 69 | is_nothrow_move_constructible<allocator_type>::value); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 70 | unordered_map(unordered_map&&, const Allocator&); |
| 71 | unordered_map(initializer_list<value_type>, size_type n = 0, |
| 72 | const hasher& hf = hasher(), const key_equal& eql = key_equal(), |
| 73 | const allocator_type& a = allocator_type()); |
Marshall Clow | 3cd37e6 | 2013-09-12 03:00:31 | [diff] [blame] | 74 | unordered_map(size_type n, const allocator_type& a) |
| 75 | : unordered_map(n, hasher(), key_equal(), a) {} // C++14 |
| 76 | unordered_map(size_type n, const hasher& hf, const allocator_type& a) |
| 77 | : unordered_map(n, hf, key_equal(), a) {} // C++14 |
| 78 | template <class InputIterator> |
| 79 | unordered_map(InputIterator f, InputIterator l, size_type n, const allocator_type& a) |
| 80 | : unordered_map(f, l, n, hasher(), key_equal(), a) {} // C++14 |
| 81 | template <class InputIterator> |
Louis Dionne | a2a1ec2 | 2019-05-29 16:01:36 | [diff] [blame] | 82 | unordered_map(InputIterator f, InputIterator l, size_type n, const hasher& hf, |
Marshall Clow | 3cd37e6 | 2013-09-12 03:00:31 | [diff] [blame] | 83 | const allocator_type& a) |
| 84 | : unordered_map(f, l, n, hf, key_equal(), a) {} // C++14 |
| 85 | unordered_map(initializer_list<value_type> il, size_type n, const allocator_type& a) |
| 86 | : unordered_map(il, n, hasher(), key_equal(), a) {} // C++14 |
Louis Dionne | a2a1ec2 | 2019-05-29 16:01:36 | [diff] [blame] | 87 | unordered_map(initializer_list<value_type> il, size_type n, const hasher& hf, |
Marshall Clow | 3cd37e6 | 2013-09-12 03:00:31 | [diff] [blame] | 88 | const allocator_type& a) |
| 89 | : unordered_map(il, n, hf, key_equal(), a) {} // C++14 |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 90 | ~unordered_map(); |
| 91 | unordered_map& operator=(const unordered_map&); |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 92 | unordered_map& operator=(unordered_map&&) |
| 93 | noexcept( |
| 94 | allocator_type::propagate_on_container_move_assignment::value && |
| 95 | is_nothrow_move_assignable<allocator_type>::value && |
| 96 | is_nothrow_move_assignable<hasher>::value && |
| 97 | is_nothrow_move_assignable<key_equal>::value); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 98 | unordered_map& operator=(initializer_list<value_type>); |
| 99 | |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 100 | allocator_type get_allocator() const noexcept; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 101 | |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 102 | bool empty() const noexcept; |
| 103 | size_type size() const noexcept; |
| 104 | size_type max_size() const noexcept; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 105 | |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 106 | iterator begin() noexcept; |
| 107 | iterator end() noexcept; |
| 108 | const_iterator begin() const noexcept; |
| 109 | const_iterator end() const noexcept; |
| 110 | const_iterator cbegin() const noexcept; |
| 111 | const_iterator cend() const noexcept; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 112 | |
| 113 | template <class... Args> |
| 114 | pair<iterator, bool> emplace(Args&&... args); |
| 115 | template <class... Args> |
| 116 | iterator emplace_hint(const_iterator position, Args&&... args); |
| 117 | pair<iterator, bool> insert(const value_type& obj); |
| 118 | template <class P> |
| 119 | pair<iterator, bool> insert(P&& obj); |
| 120 | iterator insert(const_iterator hint, const value_type& obj); |
| 121 | template <class P> |
| 122 | iterator insert(const_iterator hint, P&& obj); |
| 123 | template <class InputIterator> |
| 124 | void insert(InputIterator first, InputIterator last); |
| 125 | void insert(initializer_list<value_type>); |
| 126 | |
Erik Pilkington | b0386a5 | 2018-08-01 01:33:38 | [diff] [blame] | 127 | node_type extract(const_iterator position); // C++17 |
| 128 | node_type extract(const key_type& x); // C++17 |
| 129 | insert_return_type insert(node_type&& nh); // C++17 |
| 130 | iterator insert(const_iterator hint, node_type&& nh); // C++17 |
| 131 | |
Marshall Clow | bc4c89a | 2015-07-07 05:45:35 | [diff] [blame] | 132 | template <class... Args> |
| 133 | pair<iterator, bool> try_emplace(const key_type& k, Args&&... args); // C++17 |
| 134 | template <class... Args> |
| 135 | pair<iterator, bool> try_emplace(key_type&& k, Args&&... args); // C++17 |
| 136 | template <class... Args> |
| 137 | iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args); // C++17 |
| 138 | template <class... Args> |
| 139 | iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args); // C++17 |
| 140 | template <class M> |
| 141 | pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj); // C++17 |
| 142 | template <class M> |
| 143 | pair<iterator, bool> insert_or_assign(key_type&& k, M&& obj); // C++17 |
| 144 | template <class M> |
| 145 | iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj); // C++17 |
| 146 | template <class M> |
| 147 | iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj); // C++17 |
| 148 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 149 | iterator erase(const_iterator position); |
Marshall Clow | ec39296 | 2015-05-10 13:35:00 | [diff] [blame] | 150 | iterator erase(iterator position); // C++14 |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 151 | size_type erase(const key_type& k); |
| 152 | iterator erase(const_iterator first, const_iterator last); |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 153 | void clear() noexcept; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 154 | |
Erik Pilkington | 5c4e07a | 2018-10-31 17:31:35 | [diff] [blame] | 155 | template<class H2, class P2> |
| 156 | void merge(unordered_map<Key, T, H2, P2, Allocator>& source); // C++17 |
| 157 | template<class H2, class P2> |
| 158 | void merge(unordered_map<Key, T, H2, P2, Allocator>&& source); // C++17 |
| 159 | template<class H2, class P2> |
| 160 | void merge(unordered_multimap<Key, T, H2, P2, Allocator>& source); // C++17 |
| 161 | template<class H2, class P2> |
| 162 | void merge(unordered_multimap<Key, T, H2, P2, Allocator>&& source); // C++17 |
| 163 | |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 164 | void swap(unordered_map&) |
| 165 | noexcept( |
| 166 | (!allocator_type::propagate_on_container_swap::value || |
| 167 | __is_nothrow_swappable<allocator_type>::value) && |
| 168 | __is_nothrow_swappable<hasher>::value && |
| 169 | __is_nothrow_swappable<key_equal>::value); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 170 | |
| 171 | hasher hash_function() const; |
| 172 | key_equal key_eq() const; |
| 173 | |
| 174 | iterator find(const key_type& k); |
| 175 | const_iterator find(const key_type& k) const; |
| 176 | size_type count(const key_type& k) const; |
Zoe Carver | a17b1ae | 2019-07-16 03:21:01 | [diff] [blame] | 177 | bool contains(const key_type& k) const; // C++20 |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 178 | pair<iterator, iterator> equal_range(const key_type& k); |
| 179 | pair<const_iterator, const_iterator> equal_range(const key_type& k) const; |
| 180 | |
| 181 | mapped_type& operator[](const key_type& k); |
| 182 | mapped_type& operator[](key_type&& k); |
| 183 | |
| 184 | mapped_type& at(const key_type& k); |
| 185 | const mapped_type& at(const key_type& k) const; |
| 186 | |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 187 | size_type bucket_count() const noexcept; |
| 188 | size_type max_bucket_count() const noexcept; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 189 | |
| 190 | size_type bucket_size(size_type n) const; |
| 191 | size_type bucket(const key_type& k) const; |
| 192 | |
| 193 | local_iterator begin(size_type n); |
| 194 | local_iterator end(size_type n); |
| 195 | const_local_iterator begin(size_type n) const; |
| 196 | const_local_iterator end(size_type n) const; |
| 197 | const_local_iterator cbegin(size_type n) const; |
| 198 | const_local_iterator cend(size_type n) const; |
| 199 | |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 200 | float load_factor() const noexcept; |
| 201 | float max_load_factor() const noexcept; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 202 | void max_load_factor(float z); |
| 203 | void rehash(size_type n); |
| 204 | void reserve(size_type n); |
| 205 | }; |
| 206 | |
| 207 | template <class Key, class T, class Hash, class Pred, class Alloc> |
| 208 | void swap(unordered_map<Key, T, Hash, Pred, Alloc>& x, |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 209 | unordered_map<Key, T, Hash, Pred, Alloc>& y) |
| 210 | noexcept(noexcept(x.swap(y))); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 211 | |
| 212 | template <class Key, class T, class Hash, class Pred, class Alloc> |
| 213 | bool |
| 214 | operator==(const unordered_map<Key, T, Hash, Pred, Alloc>& x, |
| 215 | const unordered_map<Key, T, Hash, Pred, Alloc>& y); |
| 216 | |
| 217 | template <class Key, class T, class Hash, class Pred, class Alloc> |
| 218 | bool |
| 219 | operator!=(const unordered_map<Key, T, Hash, Pred, Alloc>& x, |
| 220 | const unordered_map<Key, T, Hash, Pred, Alloc>& y); |
| 221 | |
| 222 | template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>, |
| 223 | class Alloc = allocator<pair<const Key, T>>> |
| 224 | class unordered_multimap |
| 225 | { |
| 226 | public: |
| 227 | // types |
| 228 | typedef Key key_type; |
| 229 | typedef T mapped_type; |
| 230 | typedef Hash hasher; |
| 231 | typedef Pred key_equal; |
| 232 | typedef Alloc allocator_type; |
| 233 | typedef pair<const key_type, mapped_type> value_type; |
| 234 | typedef value_type& reference; |
| 235 | typedef const value_type& const_reference; |
| 236 | typedef typename allocator_traits<allocator_type>::pointer pointer; |
| 237 | typedef typename allocator_traits<allocator_type>::const_pointer const_pointer; |
| 238 | typedef typename allocator_traits<allocator_type>::size_type size_type; |
| 239 | typedef typename allocator_traits<allocator_type>::difference_type difference_type; |
| 240 | |
| 241 | typedef /unspecified/ iterator; |
| 242 | typedef /unspecified/ const_iterator; |
| 243 | typedef /unspecified/ local_iterator; |
| 244 | typedef /unspecified/ const_local_iterator; |
| 245 | |
Erik Pilkington | b0386a5 | 2018-08-01 01:33:38 | [diff] [blame] | 246 | typedef unspecified node_type; // C++17 |
| 247 | |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 248 | unordered_multimap() |
| 249 | noexcept( |
| 250 | is_nothrow_default_constructible<hasher>::value && |
| 251 | is_nothrow_default_constructible<key_equal>::value && |
| 252 | is_nothrow_default_constructible<allocator_type>::value); |
| 253 | explicit unordered_multimap(size_type n, const hasher& hf = hasher(), |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 254 | const key_equal& eql = key_equal(), |
| 255 | const allocator_type& a = allocator_type()); |
| 256 | template <class InputIterator> |
| 257 | unordered_multimap(InputIterator f, InputIterator l, |
| 258 | size_type n = 0, const hasher& hf = hasher(), |
| 259 | const key_equal& eql = key_equal(), |
| 260 | const allocator_type& a = allocator_type()); |
| 261 | explicit unordered_multimap(const allocator_type&); |
| 262 | unordered_multimap(const unordered_multimap&); |
| 263 | unordered_multimap(const unordered_multimap&, const Allocator&); |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 264 | unordered_multimap(unordered_multimap&&) |
| 265 | noexcept( |
| 266 | is_nothrow_move_constructible<hasher>::value && |
| 267 | is_nothrow_move_constructible<key_equal>::value && |
| 268 | is_nothrow_move_constructible<allocator_type>::value); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 269 | unordered_multimap(unordered_multimap&&, const Allocator&); |
| 270 | unordered_multimap(initializer_list<value_type>, size_type n = 0, |
| 271 | const hasher& hf = hasher(), const key_equal& eql = key_equal(), |
| 272 | const allocator_type& a = allocator_type()); |
Marshall Clow | 3cd37e6 | 2013-09-12 03:00:31 | [diff] [blame] | 273 | unordered_multimap(size_type n, const allocator_type& a) |
| 274 | : unordered_multimap(n, hasher(), key_equal(), a) {} // C++14 |
| 275 | unordered_multimap(size_type n, const hasher& hf, const allocator_type& a) |
| 276 | : unordered_multimap(n, hf, key_equal(), a) {} // C++14 |
| 277 | template <class InputIterator> |
| 278 | unordered_multimap(InputIterator f, InputIterator l, size_type n, const allocator_type& a) |
| 279 | : unordered_multimap(f, l, n, hasher(), key_equal(), a) {} // C++14 |
| 280 | template <class InputIterator> |
Louis Dionne | a2a1ec2 | 2019-05-29 16:01:36 | [diff] [blame] | 281 | unordered_multimap(InputIterator f, InputIterator l, size_type n, const hasher& hf, |
Marshall Clow | 3cd37e6 | 2013-09-12 03:00:31 | [diff] [blame] | 282 | const allocator_type& a) |
| 283 | : unordered_multimap(f, l, n, hf, key_equal(), a) {} // C++14 |
| 284 | unordered_multimap(initializer_list<value_type> il, size_type n, const allocator_type& a) |
| 285 | : unordered_multimap(il, n, hasher(), key_equal(), a) {} // C++14 |
Louis Dionne | a2a1ec2 | 2019-05-29 16:01:36 | [diff] [blame] | 286 | unordered_multimap(initializer_list<value_type> il, size_type n, const hasher& hf, |
Marshall Clow | 3cd37e6 | 2013-09-12 03:00:31 | [diff] [blame] | 287 | const allocator_type& a) |
| 288 | : unordered_multimap(il, n, hf, key_equal(), a) {} // C++14 |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 289 | ~unordered_multimap(); |
| 290 | unordered_multimap& operator=(const unordered_multimap&); |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 291 | unordered_multimap& operator=(unordered_multimap&&) |
| 292 | noexcept( |
| 293 | allocator_type::propagate_on_container_move_assignment::value && |
| 294 | is_nothrow_move_assignable<allocator_type>::value && |
| 295 | is_nothrow_move_assignable<hasher>::value && |
| 296 | is_nothrow_move_assignable<key_equal>::value); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 297 | unordered_multimap& operator=(initializer_list<value_type>); |
| 298 | |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 299 | allocator_type get_allocator() const noexcept; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 300 | |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 301 | bool empty() const noexcept; |
| 302 | size_type size() const noexcept; |
| 303 | size_type max_size() const noexcept; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 304 | |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 305 | iterator begin() noexcept; |
| 306 | iterator end() noexcept; |
| 307 | const_iterator begin() const noexcept; |
| 308 | const_iterator end() const noexcept; |
| 309 | const_iterator cbegin() const noexcept; |
| 310 | const_iterator cend() const noexcept; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 311 | |
| 312 | template <class... Args> |
| 313 | iterator emplace(Args&&... args); |
| 314 | template <class... Args> |
| 315 | iterator emplace_hint(const_iterator position, Args&&... args); |
| 316 | iterator insert(const value_type& obj); |
| 317 | template <class P> |
| 318 | iterator insert(P&& obj); |
| 319 | iterator insert(const_iterator hint, const value_type& obj); |
| 320 | template <class P> |
| 321 | iterator insert(const_iterator hint, P&& obj); |
| 322 | template <class InputIterator> |
| 323 | void insert(InputIterator first, InputIterator last); |
| 324 | void insert(initializer_list<value_type>); |
| 325 | |
Erik Pilkington | b0386a5 | 2018-08-01 01:33:38 | [diff] [blame] | 326 | node_type extract(const_iterator position); // C++17 |
| 327 | node_type extract(const key_type& x); // C++17 |
| 328 | iterator insert(node_type&& nh); // C++17 |
| 329 | iterator insert(const_iterator hint, node_type&& nh); // C++17 |
| 330 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 331 | iterator erase(const_iterator position); |
Marshall Clow | ec39296 | 2015-05-10 13:35:00 | [diff] [blame] | 332 | iterator erase(iterator position); // C++14 |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 333 | size_type erase(const key_type& k); |
| 334 | iterator erase(const_iterator first, const_iterator last); |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 335 | void clear() noexcept; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 336 | |
Erik Pilkington | 5c4e07a | 2018-10-31 17:31:35 | [diff] [blame] | 337 | template<class H2, class P2> |
| 338 | void merge(unordered_multimap<Key, T, H2, P2, Allocator>& source); // C++17 |
| 339 | template<class H2, class P2> |
| 340 | void merge(unordered_multimap<Key, T, H2, P2, Allocator>&& source); // C++17 |
| 341 | template<class H2, class P2> |
| 342 | void merge(unordered_map<Key, T, H2, P2, Allocator>& source); // C++17 |
| 343 | template<class H2, class P2> |
| 344 | void merge(unordered_map<Key, T, H2, P2, Allocator>&& source); // C++17 |
| 345 | |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 346 | void swap(unordered_multimap&) |
| 347 | noexcept( |
| 348 | (!allocator_type::propagate_on_container_swap::value || |
| 349 | __is_nothrow_swappable<allocator_type>::value) && |
| 350 | __is_nothrow_swappable<hasher>::value && |
| 351 | __is_nothrow_swappable<key_equal>::value); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 352 | |
| 353 | hasher hash_function() const; |
| 354 | key_equal key_eq() const; |
| 355 | |
| 356 | iterator find(const key_type& k); |
| 357 | const_iterator find(const key_type& k) const; |
| 358 | size_type count(const key_type& k) const; |
Zoe Carver | a17b1ae | 2019-07-16 03:21:01 | [diff] [blame] | 359 | bool contains(const key_type& k) const; // C++20 |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 360 | pair<iterator, iterator> equal_range(const key_type& k); |
| 361 | pair<const_iterator, const_iterator> equal_range(const key_type& k) const; |
| 362 | |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 363 | size_type bucket_count() const noexcept; |
| 364 | size_type max_bucket_count() const noexcept; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 365 | |
| 366 | size_type bucket_size(size_type n) const; |
| 367 | size_type bucket(const key_type& k) const; |
| 368 | |
| 369 | local_iterator begin(size_type n); |
| 370 | local_iterator end(size_type n); |
| 371 | const_local_iterator begin(size_type n) const; |
| 372 | const_local_iterator end(size_type n) const; |
| 373 | const_local_iterator cbegin(size_type n) const; |
| 374 | const_local_iterator cend(size_type n) const; |
| 375 | |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 376 | float load_factor() const noexcept; |
| 377 | float max_load_factor() const noexcept; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 378 | void max_load_factor(float z); |
| 379 | void rehash(size_type n); |
| 380 | void reserve(size_type n); |
| 381 | }; |
| 382 | |
| 383 | template <class Key, class T, class Hash, class Pred, class Alloc> |
| 384 | void swap(unordered_multimap<Key, T, Hash, Pred, Alloc>& x, |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 385 | unordered_multimap<Key, T, Hash, Pred, Alloc>& y) |
| 386 | noexcept(noexcept(x.swap(y))); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 387 | |
Marshall Clow | f60c63c0 | 2018-12-14 18:49:35 | [diff] [blame] | 388 | template <class K, class T, class H, class P, class A, class Predicate> |
| 389 | void erase_if(unordered_set<K, T, H, P, A>& c, Predicate pred); // C++20 |
| 390 | |
| 391 | template <class K, class T, class H, class P, class A, class Predicate> |
| 392 | void erase_if(unordered_multiset<K, T, H, P, A>& c, Predicate pred); // C++20 |
| 393 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 394 | template <class Key, class T, class Hash, class Pred, class Alloc> |
| 395 | bool |
| 396 | operator==(const unordered_multimap<Key, T, Hash, Pred, Alloc>& x, |
| 397 | const unordered_multimap<Key, T, Hash, Pred, Alloc>& y); |
| 398 | |
| 399 | template <class Key, class T, class Hash, class Pred, class Alloc> |
| 400 | bool |
| 401 | operator!=(const unordered_multimap<Key, T, Hash, Pred, Alloc>& x, |
| 402 | const unordered_multimap<Key, T, Hash, Pred, Alloc>& y); |
| 403 | |
| 404 | } // std |
| 405 | |
| 406 | */ |
| 407 | |
| 408 | #include <__config> |
| 409 | #include <__hash_table> |
Erik Pilkington | b0386a5 | 2018-08-01 01:33:38 | [diff] [blame] | 410 | #include <__node_handle> |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 411 | #include <functional> |
| 412 | #include <stdexcept> |
Eric Fiselier | 0f90567 | 2016-02-11 21:45:53 | [diff] [blame] | 413 | #include <tuple> |
Marshall Clow | f56972e | 2018-09-12 19:41:40 | [diff] [blame] | 414 | #include <version> |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 415 | |
Eric Fiselier | c1bd919 | 2014-08-10 23:53:08 | [diff] [blame] | 416 | #include <__debug> |
| 417 | |
Howard Hinnant | 073458b | 2011-10-17 20:05:10 | [diff] [blame] | 418 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 419 | #pragma GCC system_header |
Howard Hinnant | 073458b | 2011-10-17 20:05:10 | [diff] [blame] | 420 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 421 | |
| 422 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 423 | |
Louis Dionne | 3560fbf3 | 2018-12-06 21:46:17 | [diff] [blame] | 424 | template <class _Key, class _Cp, class _Hash, |
| 425 | bool = is_empty<_Hash>::value && !__libcpp_is_final<_Hash>::value> |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 426 | class __unordered_map_hasher |
| 427 | : private _Hash |
| 428 | { |
| 429 | public: |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 430 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 431 | __unordered_map_hasher() |
| 432 | _NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value) |
| 433 | : _Hash() {} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 434 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 435 | __unordered_map_hasher(const _Hash& __h) |
| 436 | _NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value) |
| 437 | : _Hash(__h) {} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 438 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 439 | const _Hash& hash_function() const _NOEXCEPT {return *this;} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 440 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a1a9e77 | 2011-12-12 17:26:24 | [diff] [blame] | 441 | size_t operator()(const _Cp& __x) const |
Erik Pilkington | f52318b | 2018-06-04 20:38:23 | [diff] [blame] | 442 | {return static_cast<const _Hash&>(*this)(__x.__get_value().first);} |
Howard Hinnant | a1a9e77 | 2011-12-12 17:26:24 | [diff] [blame] | 443 | _LIBCPP_INLINE_VISIBILITY |
| 444 | size_t operator()(const _Key& __x) const |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 445 | {return static_cast<const _Hash&>(*this)(__x);} |
Marshall Clow | e3fbe14 | 2015-07-13 20:04:56 | [diff] [blame] | 446 | void swap(__unordered_map_hasher&__y) |
| 447 | _NOEXCEPT_(__is_nothrow_swappable<_Hash>::value) |
| 448 | { |
| 449 | using _VSTD::swap; |
Eric Fiselier | b3f5742 | 2017-04-13 01:02:41 | [diff] [blame] | 450 | swap(static_cast<_Hash&>(*this), static_cast<_Hash&>(__y)); |
Marshall Clow | e3fbe14 | 2015-07-13 20:04:56 | [diff] [blame] | 451 | } |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 452 | }; |
| 453 | |
Howard Hinnant | abb160e | 2013-07-05 18:06:00 | [diff] [blame] | 454 | template <class _Key, class _Cp, class _Hash> |
| 455 | class __unordered_map_hasher<_Key, _Cp, _Hash, false> |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 456 | { |
| 457 | _Hash __hash_; |
| 458 | public: |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 459 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 460 | __unordered_map_hasher() |
| 461 | _NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value) |
| 462 | : __hash_() {} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 463 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 464 | __unordered_map_hasher(const _Hash& __h) |
| 465 | _NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value) |
| 466 | : __hash_(__h) {} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 467 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 468 | const _Hash& hash_function() const _NOEXCEPT {return __hash_;} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 469 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a1a9e77 | 2011-12-12 17:26:24 | [diff] [blame] | 470 | size_t operator()(const _Cp& __x) const |
Erik Pilkington | f52318b | 2018-06-04 20:38:23 | [diff] [blame] | 471 | {return __hash_(__x.__get_value().first);} |
Howard Hinnant | a1a9e77 | 2011-12-12 17:26:24 | [diff] [blame] | 472 | _LIBCPP_INLINE_VISIBILITY |
| 473 | size_t operator()(const _Key& __x) const |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 474 | {return __hash_(__x);} |
Marshall Clow | e3fbe14 | 2015-07-13 20:04:56 | [diff] [blame] | 475 | void swap(__unordered_map_hasher&__y) |
| 476 | _NOEXCEPT_(__is_nothrow_swappable<_Hash>::value) |
| 477 | { |
| 478 | using _VSTD::swap; |
| 479 | swap(__hash_, __y.__hash_); |
| 480 | } |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 481 | }; |
| 482 | |
Marshall Clow | e3fbe14 | 2015-07-13 20:04:56 | [diff] [blame] | 483 | template <class _Key, class _Cp, class _Hash, bool __b> |
| 484 | inline _LIBCPP_INLINE_VISIBILITY |
| 485 | void |
| 486 | swap(__unordered_map_hasher<_Key, _Cp, _Hash, __b>& __x, |
| 487 | __unordered_map_hasher<_Key, _Cp, _Hash, __b>& __y) |
| 488 | _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) |
| 489 | { |
| 490 | __x.swap(__y); |
| 491 | } |
| 492 | |
Louis Dionne | 3560fbf3 | 2018-12-06 21:46:17 | [diff] [blame] | 493 | template <class _Key, class _Cp, class _Pred, |
| 494 | bool = is_empty<_Pred>::value && !__libcpp_is_final<_Pred>::value> |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 495 | class __unordered_map_equal |
| 496 | : private _Pred |
| 497 | { |
| 498 | public: |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 499 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 500 | __unordered_map_equal() |
| 501 | _NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value) |
| 502 | : _Pred() {} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 503 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 504 | __unordered_map_equal(const _Pred& __p) |
| 505 | _NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value) |
| 506 | : _Pred(__p) {} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 507 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 508 | const _Pred& key_eq() const _NOEXCEPT {return *this;} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 509 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a1a9e77 | 2011-12-12 17:26:24 | [diff] [blame] | 510 | bool operator()(const _Cp& __x, const _Cp& __y) const |
Erik Pilkington | f52318b | 2018-06-04 20:38:23 | [diff] [blame] | 511 | {return static_cast<const _Pred&>(*this)(__x.__get_value().first, __y.__get_value().first);} |
Howard Hinnant | a1a9e77 | 2011-12-12 17:26:24 | [diff] [blame] | 512 | _LIBCPP_INLINE_VISIBILITY |
| 513 | bool operator()(const _Cp& __x, const _Key& __y) const |
Erik Pilkington | f52318b | 2018-06-04 20:38:23 | [diff] [blame] | 514 | {return static_cast<const _Pred&>(*this)(__x.__get_value().first, __y);} |
Howard Hinnant | a1a9e77 | 2011-12-12 17:26:24 | [diff] [blame] | 515 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a1a9e77 | 2011-12-12 17:26:24 | [diff] [blame] | 516 | bool operator()(const _Key& __x, const _Cp& __y) const |
Erik Pilkington | f52318b | 2018-06-04 20:38:23 | [diff] [blame] | 517 | {return static_cast<const _Pred&>(*this)(__x, __y.__get_value().first);} |
Marshall Clow | e3fbe14 | 2015-07-13 20:04:56 | [diff] [blame] | 518 | void swap(__unordered_map_equal&__y) |
| 519 | _NOEXCEPT_(__is_nothrow_swappable<_Pred>::value) |
| 520 | { |
| 521 | using _VSTD::swap; |
Eric Fiselier | b3f5742 | 2017-04-13 01:02:41 | [diff] [blame] | 522 | swap(static_cast<_Pred&>(*this), static_cast<_Pred&>(__y)); |
Marshall Clow | e3fbe14 | 2015-07-13 20:04:56 | [diff] [blame] | 523 | } |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 524 | }; |
| 525 | |
Howard Hinnant | abb160e | 2013-07-05 18:06:00 | [diff] [blame] | 526 | template <class _Key, class _Cp, class _Pred> |
| 527 | class __unordered_map_equal<_Key, _Cp, _Pred, false> |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 528 | { |
| 529 | _Pred __pred_; |
| 530 | public: |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 531 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 532 | __unordered_map_equal() |
| 533 | _NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value) |
| 534 | : __pred_() {} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 535 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 536 | __unordered_map_equal(const _Pred& __p) |
| 537 | _NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value) |
| 538 | : __pred_(__p) {} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 539 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 540 | const _Pred& key_eq() const _NOEXCEPT {return __pred_;} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 541 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a1a9e77 | 2011-12-12 17:26:24 | [diff] [blame] | 542 | bool operator()(const _Cp& __x, const _Cp& __y) const |
Erik Pilkington | f52318b | 2018-06-04 20:38:23 | [diff] [blame] | 543 | {return __pred_(__x.__get_value().first, __y.__get_value().first);} |
Howard Hinnant | a1a9e77 | 2011-12-12 17:26:24 | [diff] [blame] | 544 | _LIBCPP_INLINE_VISIBILITY |
| 545 | bool operator()(const _Cp& __x, const _Key& __y) const |
Erik Pilkington | f52318b | 2018-06-04 20:38:23 | [diff] [blame] | 546 | {return __pred_(__x.__get_value().first, __y);} |
Howard Hinnant | a1a9e77 | 2011-12-12 17:26:24 | [diff] [blame] | 547 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a1a9e77 | 2011-12-12 17:26:24 | [diff] [blame] | 548 | bool operator()(const _Key& __x, const _Cp& __y) const |
Erik Pilkington | f52318b | 2018-06-04 20:38:23 | [diff] [blame] | 549 | {return __pred_(__x, __y.__get_value().first);} |
Marshall Clow | e3fbe14 | 2015-07-13 20:04:56 | [diff] [blame] | 550 | void swap(__unordered_map_equal&__y) |
| 551 | _NOEXCEPT_(__is_nothrow_swappable<_Pred>::value) |
| 552 | { |
| 553 | using _VSTD::swap; |
| 554 | swap(__pred_, __y.__pred_); |
| 555 | } |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 556 | }; |
| 557 | |
Marshall Clow | e3fbe14 | 2015-07-13 20:04:56 | [diff] [blame] | 558 | template <class _Key, class _Cp, class _Pred, bool __b> |
| 559 | inline _LIBCPP_INLINE_VISIBILITY |
| 560 | void |
| 561 | swap(__unordered_map_equal<_Key, _Cp, _Pred, __b>& __x, |
| 562 | __unordered_map_equal<_Key, _Cp, _Pred, __b>& __y) |
| 563 | _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) |
| 564 | { |
| 565 | __x.swap(__y); |
| 566 | } |
| 567 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 568 | template <class _Alloc> |
| 569 | class __hash_map_node_destructor |
| 570 | { |
| 571 | typedef _Alloc allocator_type; |
| 572 | typedef allocator_traits<allocator_type> __alloc_traits; |
Eric Fiselier | 75d0dcf | 2016-02-10 20:46:23 | [diff] [blame] | 573 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 574 | public: |
Eric Fiselier | 75d0dcf | 2016-02-10 20:46:23 | [diff] [blame] | 575 | |
| 576 | typedef typename __alloc_traits::pointer pointer; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 577 | private: |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 578 | |
| 579 | allocator_type& __na_; |
| 580 | |
| 581 | __hash_map_node_destructor& operator=(const __hash_map_node_destructor&); |
| 582 | |
| 583 | public: |
| 584 | bool __first_constructed; |
| 585 | bool __second_constructed; |
| 586 | |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 587 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 588 | explicit __hash_map_node_destructor(allocator_type& __na) _NOEXCEPT |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 589 | : __na_(__na), |
| 590 | __first_constructed(false), |
| 591 | __second_constructed(false) |
| 592 | {} |
| 593 | |
Eric Fiselier | 6a470bc | 2017-04-18 22:50:56 | [diff] [blame] | 594 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 595 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 596 | __hash_map_node_destructor(__hash_node_destructor<allocator_type>&& __x) |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 597 | _NOEXCEPT |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 598 | : __na_(__x.__na_), |
| 599 | __first_constructed(__x.__value_constructed), |
| 600 | __second_constructed(__x.__value_constructed) |
| 601 | { |
| 602 | __x.__value_constructed = false; |
| 603 | } |
Eric Fiselier | 6a470bc | 2017-04-18 22:50:56 | [diff] [blame] | 604 | #else // _LIBCPP_CXX03_LANG |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 605 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 606 | __hash_map_node_destructor(const __hash_node_destructor<allocator_type>& __x) |
| 607 | : __na_(__x.__na_), |
| 608 | __first_constructed(__x.__value_constructed), |
| 609 | __second_constructed(__x.__value_constructed) |
| 610 | { |
| 611 | const_cast<bool&>(__x.__value_constructed) = false; |
| 612 | } |
Eric Fiselier | 6a470bc | 2017-04-18 22:50:56 | [diff] [blame] | 613 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 614 | |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 615 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 616 | void operator()(pointer __p) _NOEXCEPT |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 617 | { |
| 618 | if (__second_constructed) |
Erik Pilkington | f52318b | 2018-06-04 20:38:23 | [diff] [blame] | 619 | __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__get_value().second)); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 620 | if (__first_constructed) |
Erik Pilkington | f52318b | 2018-06-04 20:38:23 | [diff] [blame] | 621 | __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__get_value().first)); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 622 | if (__p) |
| 623 | __alloc_traits::deallocate(__na_, __p, 1); |
| 624 | } |
| 625 | }; |
| 626 | |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 | [diff] [blame] | 627 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 9fd9f84 | 2013-09-30 19:08:22 | [diff] [blame] | 628 | template <class _Key, class _Tp> |
Erik Pilkington | f52318b | 2018-06-04 20:38:23 | [diff] [blame] | 629 | struct __hash_value_type |
Howard Hinnant | 9fd9f84 | 2013-09-30 19:08:22 | [diff] [blame] | 630 | { |
| 631 | typedef _Key key_type; |
| 632 | typedef _Tp mapped_type; |
| 633 | typedef pair<const key_type, mapped_type> value_type; |
Erik Pilkington | f52318b | 2018-06-04 20:38:23 | [diff] [blame] | 634 | typedef pair<key_type&, mapped_type&> __nc_ref_pair_type; |
| 635 | typedef pair<key_type&&, mapped_type&&> __nc_rref_pair_type; |
Howard Hinnant | 9fd9f84 | 2013-09-30 19:08:22 | [diff] [blame] | 636 | |
Erik Pilkington | f52318b | 2018-06-04 20:38:23 | [diff] [blame] | 637 | private: |
Howard Hinnant | 9fd9f84 | 2013-09-30 19:08:22 | [diff] [blame] | 638 | value_type __cc; |
Erik Pilkington | f52318b | 2018-06-04 20:38:23 | [diff] [blame] | 639 | |
| 640 | public: |
| 641 | _LIBCPP_INLINE_VISIBILITY |
| 642 | value_type& __get_value() |
| 643 | { |
| 644 | #if _LIBCPP_STD_VER > 14 |
| 645 | return *_VSTD::launder(_VSTD::addressof(__cc)); |
| 646 | #else |
| 647 | return __cc; |
| 648 | #endif |
| 649 | } |
| 650 | |
| 651 | _LIBCPP_INLINE_VISIBILITY |
| 652 | const value_type& __get_value() const |
| 653 | { |
| 654 | #if _LIBCPP_STD_VER > 14 |
| 655 | return *_VSTD::launder(_VSTD::addressof(__cc)); |
| 656 | #else |
| 657 | return __cc; |
| 658 | #endif |
| 659 | } |
| 660 | |
| 661 | _LIBCPP_INLINE_VISIBILITY |
| 662 | __nc_ref_pair_type __ref() |
| 663 | { |
| 664 | value_type& __v = __get_value(); |
| 665 | return __nc_ref_pair_type(const_cast<key_type&>(__v.first), __v.second); |
| 666 | } |
| 667 | |
| 668 | _LIBCPP_INLINE_VISIBILITY |
| 669 | __nc_rref_pair_type __move() |
| 670 | { |
| 671 | value_type& __v = __get_value(); |
| 672 | return __nc_rref_pair_type( |
| 673 | _VSTD::move(const_cast<key_type&>(__v.first)), |
| 674 | _VSTD::move(__v.second)); |
| 675 | } |
Howard Hinnant | 9fd9f84 | 2013-09-30 19:08:22 | [diff] [blame] | 676 | |
Howard Hinnant | 9fd9f84 | 2013-09-30 19:08:22 | [diff] [blame] | 677 | _LIBCPP_INLINE_VISIBILITY |
| 678 | __hash_value_type& operator=(const __hash_value_type& __v) |
Erik Pilkington | f52318b | 2018-06-04 20:38:23 | [diff] [blame] | 679 | { |
| 680 | __ref() = __v.__get_value(); |
| 681 | return *this; |
| 682 | } |
Howard Hinnant | 9fd9f84 | 2013-09-30 19:08:22 | [diff] [blame] | 683 | |
| 684 | _LIBCPP_INLINE_VISIBILITY |
| 685 | __hash_value_type& operator=(__hash_value_type&& __v) |
Erik Pilkington | f52318b | 2018-06-04 20:38:23 | [diff] [blame] | 686 | { |
| 687 | __ref() = __v.__move(); |
| 688 | return *this; |
| 689 | } |
Howard Hinnant | 9fd9f84 | 2013-09-30 19:08:22 | [diff] [blame] | 690 | |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 | [diff] [blame] | 691 | template <class _ValueTp, |
| 692 | class = typename enable_if< |
| 693 | __is_same_uncvref<_ValueTp, value_type>::value |
| 694 | >::type |
| 695 | > |
Howard Hinnant | 9fd9f84 | 2013-09-30 19:08:22 | [diff] [blame] | 696 | _LIBCPP_INLINE_VISIBILITY |
Erik Pilkington | f52318b | 2018-06-04 20:38:23 | [diff] [blame] | 697 | __hash_value_type& operator=(_ValueTp&& __v) |
| 698 | { |
| 699 | __ref() = _VSTD::forward<_ValueTp>(__v); |
| 700 | return *this; |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | private: |
| 704 | __hash_value_type(const __hash_value_type& __v) = delete; |
| 705 | __hash_value_type(__hash_value_type&& __v) = delete; |
| 706 | template <class ..._Args> |
| 707 | explicit __hash_value_type(_Args&& ...__args) = delete; |
| 708 | |
| 709 | ~__hash_value_type() = delete; |
Howard Hinnant | 9fd9f84 | 2013-09-30 19:08:22 | [diff] [blame] | 710 | }; |
| 711 | |
| 712 | #else |
| 713 | |
| 714 | template <class _Key, class _Tp> |
| 715 | struct __hash_value_type |
| 716 | { |
| 717 | typedef _Key key_type; |
| 718 | typedef _Tp mapped_type; |
| 719 | typedef pair<const key_type, mapped_type> value_type; |
| 720 | |
Erik Pilkington | f52318b | 2018-06-04 20:38:23 | [diff] [blame] | 721 | private: |
Howard Hinnant | 9fd9f84 | 2013-09-30 19:08:22 | [diff] [blame] | 722 | value_type __cc; |
| 723 | |
Erik Pilkington | f52318b | 2018-06-04 20:38:23 | [diff] [blame] | 724 | public: |
| 725 | _LIBCPP_INLINE_VISIBILITY |
| 726 | value_type& __get_value() { return __cc; } |
| 727 | _LIBCPP_INLINE_VISIBILITY |
| 728 | const value_type& __get_value() const { return __cc; } |
| 729 | |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 | [diff] [blame] | 730 | private: |
| 731 | ~__hash_value_type(); |
Howard Hinnant | 9fd9f84 | 2013-09-30 19:08:22 | [diff] [blame] | 732 | }; |
| 733 | |
| 734 | #endif |
| 735 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 736 | template <class _HashIterator> |
Eric Fiselier | e2f2d1ed | 2017-01-04 23:56:00 | [diff] [blame] | 737 | class _LIBCPP_TEMPLATE_VIS __hash_map_iterator |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 738 | { |
| 739 | _HashIterator __i_; |
| 740 | |
Eric Fiselier | 75d0dcf | 2016-02-10 20:46:23 | [diff] [blame] | 741 | typedef __hash_node_types_from_iterator<_HashIterator> _NodeTypes; |
| 742 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 743 | public: |
| 744 | typedef forward_iterator_tag iterator_category; |
Eric Fiselier | 75d0dcf | 2016-02-10 20:46:23 | [diff] [blame] | 745 | typedef typename _NodeTypes::__map_value_type value_type; |
| 746 | typedef typename _NodeTypes::difference_type difference_type; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 747 | typedef value_type& reference; |
Eric Fiselier | 75d0dcf | 2016-02-10 20:46:23 | [diff] [blame] | 748 | typedef typename _NodeTypes::__map_value_type_pointer pointer; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 749 | |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 750 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 751 | __hash_map_iterator() _NOEXCEPT {} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 752 | |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 753 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 754 | __hash_map_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 755 | |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 756 | _LIBCPP_INLINE_VISIBILITY |
Erik Pilkington | f52318b | 2018-06-04 20:38:23 | [diff] [blame] | 757 | reference operator*() const {return __i_->__get_value();} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 758 | _LIBCPP_INLINE_VISIBILITY |
Erik Pilkington | f52318b | 2018-06-04 20:38:23 | [diff] [blame] | 759 | pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 760 | |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 761 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 762 | __hash_map_iterator& operator++() {++__i_; return *this;} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 763 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 764 | __hash_map_iterator operator++(int) |
| 765 | { |
| 766 | __hash_map_iterator __t(*this); |
| 767 | ++(*this); |
| 768 | return __t; |
| 769 | } |
| 770 | |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 771 | friend _LIBCPP_INLINE_VISIBILITY |
| 772 | bool operator==(const __hash_map_iterator& __x, const __hash_map_iterator& __y) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 773 | {return __x.__i_ == __y.__i_;} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 774 | friend _LIBCPP_INLINE_VISIBILITY |
| 775 | bool operator!=(const __hash_map_iterator& __x, const __hash_map_iterator& __y) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 776 | {return __x.__i_ != __y.__i_;} |
| 777 | |
Eric Fiselier | e2f2d1ed | 2017-01-04 23:56:00 | [diff] [blame] | 778 | template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map; |
| 779 | template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_multimap; |
| 780 | template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator; |
| 781 | template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator; |
| 782 | template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 783 | }; |
| 784 | |
| 785 | template <class _HashIterator> |
Eric Fiselier | e2f2d1ed | 2017-01-04 23:56:00 | [diff] [blame] | 786 | class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 787 | { |
| 788 | _HashIterator __i_; |
| 789 | |
Eric Fiselier | 75d0dcf | 2016-02-10 20:46:23 | [diff] [blame] | 790 | typedef __hash_node_types_from_iterator<_HashIterator> _NodeTypes; |
| 791 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 792 | public: |
| 793 | typedef forward_iterator_tag iterator_category; |
Eric Fiselier | 75d0dcf | 2016-02-10 20:46:23 | [diff] [blame] | 794 | typedef typename _NodeTypes::__map_value_type value_type; |
| 795 | typedef typename _NodeTypes::difference_type difference_type; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 796 | typedef const value_type& reference; |
Eric Fiselier | 75d0dcf | 2016-02-10 20:46:23 | [diff] [blame] | 797 | typedef typename _NodeTypes::__const_map_value_type_pointer pointer; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 798 | |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 799 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 800 | __hash_map_const_iterator() _NOEXCEPT {} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 801 | |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 802 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 803 | __hash_map_const_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 804 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 805 | __hash_map_const_iterator( |
| 806 | __hash_map_iterator<typename _HashIterator::__non_const_iterator> __i) |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 807 | _NOEXCEPT |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 808 | : __i_(__i.__i_) {} |
| 809 | |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 810 | _LIBCPP_INLINE_VISIBILITY |
Erik Pilkington | f52318b | 2018-06-04 20:38:23 | [diff] [blame] | 811 | reference operator*() const {return __i_->__get_value();} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 812 | _LIBCPP_INLINE_VISIBILITY |
Erik Pilkington | f52318b | 2018-06-04 20:38:23 | [diff] [blame] | 813 | pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 814 | |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 815 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 816 | __hash_map_const_iterator& operator++() {++__i_; return *this;} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 817 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 818 | __hash_map_const_iterator operator++(int) |
| 819 | { |
| 820 | __hash_map_const_iterator __t(*this); |
| 821 | ++(*this); |
| 822 | return __t; |
| 823 | } |
| 824 | |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 825 | friend _LIBCPP_INLINE_VISIBILITY |
| 826 | bool operator==(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 827 | {return __x.__i_ == __y.__i_;} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 828 | friend _LIBCPP_INLINE_VISIBILITY |
| 829 | bool operator!=(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 830 | {return __x.__i_ != __y.__i_;} |
| 831 | |
Eric Fiselier | e2f2d1ed | 2017-01-04 23:56:00 | [diff] [blame] | 832 | template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map; |
| 833 | template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_multimap; |
| 834 | template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator; |
| 835 | template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 836 | }; |
| 837 | |
Erik Pilkington | 5c4e07a | 2018-10-31 17:31:35 | [diff] [blame] | 838 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 839 | class unordered_multimap; |
| 840 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 841 | template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>, |
| 842 | class _Alloc = allocator<pair<const _Key, _Tp> > > |
Eric Fiselier | e2f2d1ed | 2017-01-04 23:56:00 | [diff] [blame] | 843 | class _LIBCPP_TEMPLATE_VIS unordered_map |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 844 | { |
| 845 | public: |
| 846 | // types |
| 847 | typedef _Key key_type; |
| 848 | typedef _Tp mapped_type; |
Louis Dionne | dfcd438 | 2019-07-15 20:06:01 | [diff] [blame] | 849 | typedef typename __identity<_Hash>::type hasher; |
| 850 | typedef typename __identity<_Pred>::type key_equal; |
| 851 | typedef typename __identity<_Alloc>::type allocator_type; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 852 | typedef pair<const key_type, mapped_type> value_type; |
| 853 | typedef value_type& reference; |
| 854 | typedef const value_type& const_reference; |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 | [diff] [blame] | 855 | static_assert((is_same<value_type, typename allocator_type::value_type>::value), |
| 856 | "Invalid allocator::value_type"); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 857 | |
| 858 | private: |
Howard Hinnant | 9fd9f84 | 2013-09-30 19:08:22 | [diff] [blame] | 859 | typedef __hash_value_type<key_type, mapped_type> __value_type; |
Howard Hinnant | abb160e | 2013-07-05 18:06:00 | [diff] [blame] | 860 | typedef __unordered_map_hasher<key_type, __value_type, hasher> __hasher; |
| 861 | typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal; |
Marshall Clow | 1f50801 | 2015-04-07 05:21:38 | [diff] [blame] | 862 | typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>, |
| 863 | __value_type>::type __allocator_type; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 864 | |
| 865 | typedef __hash_table<__value_type, __hasher, |
| 866 | __key_equal, __allocator_type> __table; |
| 867 | |
| 868 | __table __table_; |
| 869 | |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 | [diff] [blame] | 870 | typedef typename __table::_NodeTypes _NodeTypes; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 871 | typedef typename __table::__node_pointer __node_pointer; |
| 872 | typedef typename __table::__node_const_pointer __node_const_pointer; |
| 873 | typedef typename __table::__node_traits __node_traits; |
| 874 | typedef typename __table::__node_allocator __node_allocator; |
| 875 | typedef typename __table::__node __node; |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 | [diff] [blame] | 876 | typedef __hash_map_node_destructor<__node_allocator> _Dp; |
| 877 | typedef unique_ptr<__node, _Dp> __node_holder; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 878 | typedef allocator_traits<allocator_type> __alloc_traits; |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 | [diff] [blame] | 879 | |
| 880 | static_assert((is_same<typename __table::__container_value_type, value_type>::value), ""); |
| 881 | static_assert((is_same<typename __table::__node_value_type, __value_type>::value), ""); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 882 | public: |
| 883 | typedef typename __alloc_traits::pointer pointer; |
| 884 | typedef typename __alloc_traits::const_pointer const_pointer; |
Eric Fiselier | 75d0dcf | 2016-02-10 20:46:23 | [diff] [blame] | 885 | typedef typename __table::size_type size_type; |
| 886 | typedef typename __table::difference_type difference_type; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 887 | |
| 888 | typedef __hash_map_iterator<typename __table::iterator> iterator; |
| 889 | typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator; |
| 890 | typedef __hash_map_iterator<typename __table::local_iterator> local_iterator; |
| 891 | typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator; |
| 892 | |
Erik Pilkington | b0386a5 | 2018-08-01 01:33:38 | [diff] [blame] | 893 | #if _LIBCPP_STD_VER > 14 |
| 894 | typedef __map_node_handle<__node, allocator_type> node_type; |
| 895 | typedef __insert_return_type<iterator, node_type> insert_return_type; |
| 896 | #endif |
| 897 | |
Erik Pilkington | 5c4e07a | 2018-10-31 17:31:35 | [diff] [blame] | 898 | template <class _Key2, class _Tp2, class _Hash2, class _Pred2, class _Alloc2> |
| 899 | friend class _LIBCPP_TEMPLATE_VIS unordered_map; |
| 900 | template <class _Key2, class _Tp2, class _Hash2, class _Pred2, class _Alloc2> |
| 901 | friend class _LIBCPP_TEMPLATE_VIS unordered_multimap; |
| 902 | |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 903 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 904 | unordered_map() |
| 905 | _NOEXCEPT_(is_nothrow_default_constructible<__table>::value) |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 | [diff] [blame] | 906 | { |
| 907 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 908 | __get_db()->__insert_c(this); |
| 909 | #endif |
| 910 | } |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 911 | explicit unordered_map(size_type __n, const hasher& __hf = hasher(), |
| 912 | const key_equal& __eql = key_equal()); |
| 913 | unordered_map(size_type __n, const hasher& __hf, |
| 914 | const key_equal& __eql, |
| 915 | const allocator_type& __a); |
| 916 | template <class _InputIterator> |
| 917 | unordered_map(_InputIterator __first, _InputIterator __last); |
| 918 | template <class _InputIterator> |
| 919 | unordered_map(_InputIterator __first, _InputIterator __last, |
| 920 | size_type __n, const hasher& __hf = hasher(), |
| 921 | const key_equal& __eql = key_equal()); |
| 922 | template <class _InputIterator> |
| 923 | unordered_map(_InputIterator __first, _InputIterator __last, |
| 924 | size_type __n, const hasher& __hf, |
| 925 | const key_equal& __eql, |
| 926 | const allocator_type& __a); |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 | [diff] [blame] | 927 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 928 | explicit unordered_map(const allocator_type& __a); |
| 929 | unordered_map(const unordered_map& __u); |
| 930 | unordered_map(const unordered_map& __u, const allocator_type& __a); |
Eric Fiselier | 6a470bc | 2017-04-18 22:50:56 | [diff] [blame] | 931 | #ifndef _LIBCPP_CXX03_LANG |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 | [diff] [blame] | 932 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 933 | unordered_map(unordered_map&& __u) |
| 934 | _NOEXCEPT_(is_nothrow_move_constructible<__table>::value); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 935 | unordered_map(unordered_map&& __u, const allocator_type& __a); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 936 | unordered_map(initializer_list<value_type> __il); |
| 937 | unordered_map(initializer_list<value_type> __il, size_type __n, |
| 938 | const hasher& __hf = hasher(), const key_equal& __eql = key_equal()); |
| 939 | unordered_map(initializer_list<value_type> __il, size_type __n, |
| 940 | const hasher& __hf, const key_equal& __eql, |
| 941 | const allocator_type& __a); |
Eric Fiselier | 6a470bc | 2017-04-18 22:50:56 | [diff] [blame] | 942 | #endif // _LIBCPP_CXX03_LANG |
Marshall Clow | 3cd37e6 | 2013-09-12 03:00:31 | [diff] [blame] | 943 | #if _LIBCPP_STD_VER > 11 |
| 944 | _LIBCPP_INLINE_VISIBILITY |
| 945 | unordered_map(size_type __n, const allocator_type& __a) |
| 946 | : unordered_map(__n, hasher(), key_equal(), __a) {} |
| 947 | _LIBCPP_INLINE_VISIBILITY |
| 948 | unordered_map(size_type __n, const hasher& __hf, const allocator_type& __a) |
| 949 | : unordered_map(__n, __hf, key_equal(), __a) {} |
| 950 | template <class _InputIterator> |
| 951 | _LIBCPP_INLINE_VISIBILITY |
| 952 | unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a) |
| 953 | : unordered_map(__first, __last, __n, hasher(), key_equal(), __a) {} |
| 954 | template <class _InputIterator> |
| 955 | _LIBCPP_INLINE_VISIBILITY |
Louis Dionne | a2a1ec2 | 2019-05-29 16:01:36 | [diff] [blame] | 956 | unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf, |
Marshall Clow | 3cd37e6 | 2013-09-12 03:00:31 | [diff] [blame] | 957 | const allocator_type& __a) |
| 958 | : unordered_map(__first, __last, __n, __hf, key_equal(), __a) {} |
| 959 | _LIBCPP_INLINE_VISIBILITY |
| 960 | unordered_map(initializer_list<value_type> __il, size_type __n, const allocator_type& __a) |
| 961 | : unordered_map(__il, __n, hasher(), key_equal(), __a) {} |
| 962 | _LIBCPP_INLINE_VISIBILITY |
Louis Dionne | a2a1ec2 | 2019-05-29 16:01:36 | [diff] [blame] | 963 | unordered_map(initializer_list<value_type> __il, size_type __n, const hasher& __hf, |
Marshall Clow | 3cd37e6 | 2013-09-12 03:00:31 | [diff] [blame] | 964 | const allocator_type& __a) |
| 965 | : unordered_map(__il, __n, __hf, key_equal(), __a) {} |
| 966 | #endif |
Louis Dionne | 7c142fc | 2019-04-11 16:14:56 | [diff] [blame] | 967 | _LIBCPP_INLINE_VISIBILITY |
| 968 | ~unordered_map() { |
| 969 | static_assert(sizeof(__diagnose_unordered_container_requirements<_Key, _Hash, _Pred>(0)), ""); |
| 970 | } |
| 971 | |
Howard Hinnant | 5a33687 | 2011-07-01 19:24:36 | [diff] [blame] | 972 | _LIBCPP_INLINE_VISIBILITY |
| 973 | unordered_map& operator=(const unordered_map& __u) |
| 974 | { |
Marshall Clow | 2ee8372 | 2016-07-18 13:19:00 | [diff] [blame] | 975 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 5a33687 | 2011-07-01 19:24:36 | [diff] [blame] | 976 | __table_ = __u.__table_; |
Howard Hinnant | 307f814 | 2013-06-22 15:21:29 | [diff] [blame] | 977 | #else |
Marshall Clow | 74cf6ff | 2014-02-08 04:03:14 | [diff] [blame] | 978 | if (this != &__u) { |
| 979 | __table_.clear(); |
| 980 | __table_.hash_function() = __u.__table_.hash_function(); |
| 981 | __table_.key_eq() = __u.__table_.key_eq(); |
| 982 | __table_.max_load_factor() = __u.__table_.max_load_factor(); |
| 983 | __table_.__copy_assign_alloc(__u.__table_); |
| 984 | insert(__u.begin(), __u.end()); |
| 985 | } |
Howard Hinnant | 307f814 | 2013-06-22 15:21:29 | [diff] [blame] | 986 | #endif |
Howard Hinnant | 5a33687 | 2011-07-01 19:24:36 | [diff] [blame] | 987 | return *this; |
| 988 | } |
Eric Fiselier | 6a470bc | 2017-04-18 22:50:56 | [diff] [blame] | 989 | #ifndef _LIBCPP_CXX03_LANG |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 | [diff] [blame] | 990 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 991 | unordered_map& operator=(unordered_map&& __u) |
| 992 | _NOEXCEPT_(is_nothrow_move_assignable<__table>::value); |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 | [diff] [blame] | 993 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 994 | unordered_map& operator=(initializer_list<value_type> __il); |
Eric Fiselier | 6a470bc | 2017-04-18 22:50:56 | [diff] [blame] | 995 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 996 | |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 997 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 998 | allocator_type get_allocator() const _NOEXCEPT |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 999 | {return allocator_type(__table_.__node_alloc());} |
| 1000 | |
Marshall Clow | 72c8fad | 2017-11-15 05:51:26 | [diff] [blame] | 1001 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 1002 | bool empty() const _NOEXCEPT {return __table_.size() == 0;} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1003 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 1004 | size_type size() const _NOEXCEPT {return __table_.size();} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1005 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 1006 | size_type max_size() const _NOEXCEPT {return __table_.max_size();} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1007 | |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1008 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 1009 | iterator begin() _NOEXCEPT {return __table_.begin();} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1010 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 1011 | iterator end() _NOEXCEPT {return __table_.end();} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1012 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 1013 | const_iterator begin() const _NOEXCEPT {return __table_.begin();} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1014 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 1015 | const_iterator end() const _NOEXCEPT {return __table_.end();} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1016 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 1017 | const_iterator cbegin() const _NOEXCEPT {return __table_.begin();} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1018 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 1019 | const_iterator cend() const _NOEXCEPT {return __table_.end();} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1020 | |
Eric Fiselier | 7a9f500 | 2016-04-18 01:40:45 | [diff] [blame] | 1021 | _LIBCPP_INLINE_VISIBILITY |
| 1022 | pair<iterator, bool> insert(const value_type& __x) |
| 1023 | {return __table_.__insert_unique(__x);} |
| 1024 | |
| 1025 | iterator insert(const_iterator __p, const value_type& __x) { |
| 1026 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1027 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, |
| 1028 | "unordered_map::insert(const_iterator, const value_type&) called with an iterator not" |
| 1029 | " referring to this unordered_map"); |
Eric Fiselier | fd83822 | 2016-12-23 23:37:52 | [diff] [blame] | 1030 | #else |
| 1031 | ((void)__p); |
Eric Fiselier | 7a9f500 | 2016-04-18 01:40:45 | [diff] [blame] | 1032 | #endif |
| 1033 | return insert(__x).first; |
| 1034 | } |
| 1035 | |
| 1036 | template <class _InputIterator> |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 | [diff] [blame] | 1037 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 7a9f500 | 2016-04-18 01:40:45 | [diff] [blame] | 1038 | void insert(_InputIterator __first, _InputIterator __last); |
| 1039 | |
Eric Fiselier | 6a470bc | 2017-04-18 22:50:56 | [diff] [blame] | 1040 | #ifndef _LIBCPP_CXX03_LANG |
Eric Fiselier | 7a9f500 | 2016-04-18 01:40:45 | [diff] [blame] | 1041 | _LIBCPP_INLINE_VISIBILITY |
| 1042 | void insert(initializer_list<value_type> __il) |
| 1043 | {insert(__il.begin(), __il.end());} |
Eric Fiselier | 7a9f500 | 2016-04-18 01:40:45 | [diff] [blame] | 1044 | |
Eric Fiselier | 7a9f500 | 2016-04-18 01:40:45 | [diff] [blame] | 1045 | _LIBCPP_INLINE_VISIBILITY |
| 1046 | pair<iterator, bool> insert(value_type&& __x) |
| 1047 | {return __table_.__insert_unique(_VSTD::move(__x));} |
| 1048 | |
| 1049 | iterator insert(const_iterator __p, value_type&& __x) { |
| 1050 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1051 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, |
| 1052 | "unordered_map::insert(const_iterator, const value_type&) called with an iterator not" |
| 1053 | " referring to this unordered_map"); |
Eric Fiselier | fd83822 | 2016-12-23 23:37:52 | [diff] [blame] | 1054 | #else |
| 1055 | ((void)__p); |
Eric Fiselier | 7a9f500 | 2016-04-18 01:40:45 | [diff] [blame] | 1056 | #endif |
| 1057 | return __table_.__insert_unique(_VSTD::move(__x)).first; |
| 1058 | } |
| 1059 | |
| 1060 | template <class _Pp, |
| 1061 | class = typename enable_if<is_constructible<value_type, _Pp>::value>::type> |
| 1062 | _LIBCPP_INLINE_VISIBILITY |
| 1063 | pair<iterator, bool> insert(_Pp&& __x) |
| 1064 | {return __table_.__insert_unique(_VSTD::forward<_Pp>(__x));} |
| 1065 | |
| 1066 | template <class _Pp, |
| 1067 | class = typename enable_if<is_constructible<value_type, _Pp>::value>::type> |
| 1068 | _LIBCPP_INLINE_VISIBILITY |
| 1069 | iterator insert(const_iterator __p, _Pp&& __x) |
| 1070 | { |
| 1071 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1072 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, |
| 1073 | "unordered_map::insert(const_iterator, value_type&&) called with an iterator not" |
| 1074 | " referring to this unordered_map"); |
Eric Fiselier | fd83822 | 2016-12-23 23:37:52 | [diff] [blame] | 1075 | #else |
| 1076 | ((void)__p); |
Eric Fiselier | 7a9f500 | 2016-04-18 01:40:45 | [diff] [blame] | 1077 | #endif |
| 1078 | return insert(_VSTD::forward<_Pp>(__x)).first; |
| 1079 | } |
| 1080 | |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 | [diff] [blame] | 1081 | template <class... _Args> |
| 1082 | _LIBCPP_INLINE_VISIBILITY |
| 1083 | pair<iterator, bool> emplace(_Args&&... __args) { |
| 1084 | return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...); |
| 1085 | } |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 | [diff] [blame] | 1086 | |
Howard Hinnant | 8b805c9 | 2012-05-25 22:04:21 | [diff] [blame] | 1087 | template <class... _Args> |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 | [diff] [blame] | 1088 | _LIBCPP_INLINE_VISIBILITY |
| 1089 | iterator emplace_hint(const_iterator __p, _Args&&... __args) { |
Howard Hinnant | 4c80bfb | 2013-07-30 21:04:42 | [diff] [blame] | 1090 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 | [diff] [blame] | 1091 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, |
| 1092 | "unordered_map::emplace_hint(const_iterator, args...) called with an iterator not" |
| 1093 | " referring to this unordered_map"); |
Eric Fiselier | fd83822 | 2016-12-23 23:37:52 | [diff] [blame] | 1094 | #else |
| 1095 | ((void)__p); |
Howard Hinnant | 4c80bfb | 2013-07-30 21:04:42 | [diff] [blame] | 1096 | #endif |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 | [diff] [blame] | 1097 | return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first; |
| 1098 | } |
| 1099 | |
Eric Fiselier | 7a9f500 | 2016-04-18 01:40:45 | [diff] [blame] | 1100 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1101 | |
Marshall Clow | bc4c89a | 2015-07-07 05:45:35 | [diff] [blame] | 1102 | #if _LIBCPP_STD_VER > 14 |
Marshall Clow | bc4c89a | 2015-07-07 05:45:35 | [diff] [blame] | 1103 | template <class... _Args> |
| 1104 | _LIBCPP_INLINE_VISIBILITY |
| 1105 | pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args) |
| 1106 | { |
Eric Fiselier | 87c4104 | 2016-04-18 06:51:33 | [diff] [blame] | 1107 | return __table_.__emplace_unique_key_args(__k, _VSTD::piecewise_construct, |
| 1108 | _VSTD::forward_as_tuple(__k), |
| 1109 | _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)); |
Marshall Clow | bc4c89a | 2015-07-07 05:45:35 | [diff] [blame] | 1110 | } |
| 1111 | |
| 1112 | template <class... _Args> |
| 1113 | _LIBCPP_INLINE_VISIBILITY |
| 1114 | pair<iterator, bool> try_emplace(key_type&& __k, _Args&&... __args) |
| 1115 | { |
Eric Fiselier | 87c4104 | 2016-04-18 06:51:33 | [diff] [blame] | 1116 | return __table_.__emplace_unique_key_args(__k, _VSTD::piecewise_construct, |
| 1117 | _VSTD::forward_as_tuple(_VSTD::move(__k)), |
| 1118 | _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)); |
Marshall Clow | bc4c89a | 2015-07-07 05:45:35 | [diff] [blame] | 1119 | } |
| 1120 | |
| 1121 | template <class... _Args> |
| 1122 | _LIBCPP_INLINE_VISIBILITY |
| 1123 | iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args) |
| 1124 | { |
Eric Fiselier | 87c4104 | 2016-04-18 06:51:33 | [diff] [blame] | 1125 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Oleg Ranevskyy | eef9b35 | 2016-09-26 21:39:38 | [diff] [blame] | 1126 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__h) == this, |
Eric Fiselier | 87c4104 | 2016-04-18 06:51:33 | [diff] [blame] | 1127 | "unordered_map::try_emplace(const_iterator, key, args...) called with an iterator not" |
| 1128 | " referring to this unordered_map"); |
Eric Fiselier | fd83822 | 2016-12-23 23:37:52 | [diff] [blame] | 1129 | #else |
| 1130 | ((void)__h); |
Eric Fiselier | 87c4104 | 2016-04-18 06:51:33 | [diff] [blame] | 1131 | #endif |
Eric Fiselier | fd83822 | 2016-12-23 23:37:52 | [diff] [blame] | 1132 | return try_emplace(__k, _VSTD::forward<_Args>(__args)...).first; |
Marshall Clow | bc4c89a | 2015-07-07 05:45:35 | [diff] [blame] | 1133 | } |
| 1134 | |
| 1135 | template <class... _Args> |
| 1136 | _LIBCPP_INLINE_VISIBILITY |
| 1137 | iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args) |
| 1138 | { |
Eric Fiselier | 87c4104 | 2016-04-18 06:51:33 | [diff] [blame] | 1139 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Oleg Ranevskyy | eef9b35 | 2016-09-26 21:39:38 | [diff] [blame] | 1140 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__h) == this, |
Eric Fiselier | 87c4104 | 2016-04-18 06:51:33 | [diff] [blame] | 1141 | "unordered_map::try_emplace(const_iterator, key, args...) called with an iterator not" |
| 1142 | " referring to this unordered_map"); |
Eric Fiselier | fd83822 | 2016-12-23 23:37:52 | [diff] [blame] | 1143 | #else |
| 1144 | ((void)__h); |
Eric Fiselier | 87c4104 | 2016-04-18 06:51:33 | [diff] [blame] | 1145 | #endif |
| 1146 | return try_emplace(_VSTD::move(__k), _VSTD::forward<_Args>(__args)...).first; |
Marshall Clow | bc4c89a | 2015-07-07 05:45:35 | [diff] [blame] | 1147 | } |
| 1148 | |
| 1149 | template <class _Vp> |
| 1150 | _LIBCPP_INLINE_VISIBILITY |
| 1151 | pair<iterator, bool> insert_or_assign(const key_type& __k, _Vp&& __v) |
| 1152 | { |
Eric Fiselier | 87c4104 | 2016-04-18 06:51:33 | [diff] [blame] | 1153 | pair<iterator, bool> __res = __table_.__emplace_unique_key_args(__k, |
| 1154 | __k, _VSTD::forward<_Vp>(__v)); |
| 1155 | if (!__res.second) { |
| 1156 | __res.first->second = _VSTD::forward<_Vp>(__v); |
Marshall Clow | bc4c89a | 2015-07-07 05:45:35 | [diff] [blame] | 1157 | } |
Eric Fiselier | 87c4104 | 2016-04-18 06:51:33 | [diff] [blame] | 1158 | return __res; |
Marshall Clow | bc4c89a | 2015-07-07 05:45:35 | [diff] [blame] | 1159 | } |
Eric Fiselier | 87c4104 | 2016-04-18 06:51:33 | [diff] [blame] | 1160 | |
Marshall Clow | bc4c89a | 2015-07-07 05:45:35 | [diff] [blame] | 1161 | template <class _Vp> |
| 1162 | _LIBCPP_INLINE_VISIBILITY |
| 1163 | pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v) |
| 1164 | { |
Eric Fiselier | 87c4104 | 2016-04-18 06:51:33 | [diff] [blame] | 1165 | pair<iterator, bool> __res = __table_.__emplace_unique_key_args(__k, |
| 1166 | _VSTD::move(__k), _VSTD::forward<_Vp>(__v)); |
| 1167 | if (!__res.second) { |
| 1168 | __res.first->second = _VSTD::forward<_Vp>(__v); |
Marshall Clow | bc4c89a | 2015-07-07 05:45:35 | [diff] [blame] | 1169 | } |
Eric Fiselier | 87c4104 | 2016-04-18 06:51:33 | [diff] [blame] | 1170 | return __res; |
Marshall Clow | bc4c89a | 2015-07-07 05:45:35 | [diff] [blame] | 1171 | } |
| 1172 | |
| 1173 | template <class _Vp> |
| 1174 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | fd83822 | 2016-12-23 23:37:52 | [diff] [blame] | 1175 | iterator insert_or_assign(const_iterator, const key_type& __k, _Vp&& __v) |
Marshall Clow | bc4c89a | 2015-07-07 05:45:35 | [diff] [blame] | 1176 | { |
Eric Fiselier | fd83822 | 2016-12-23 23:37:52 | [diff] [blame] | 1177 | // FIXME: Add debug mode checking for the iterator input |
Eric Fiselier | 87c4104 | 2016-04-18 06:51:33 | [diff] [blame] | 1178 | return insert_or_assign(__k, _VSTD::forward<_Vp>(__v)).first; |
Marshall Clow | bc4c89a | 2015-07-07 05:45:35 | [diff] [blame] | 1179 | } |
| 1180 | |
| 1181 | template <class _Vp> |
| 1182 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | fd83822 | 2016-12-23 23:37:52 | [diff] [blame] | 1183 | iterator insert_or_assign(const_iterator, key_type&& __k, _Vp&& __v) |
Marshall Clow | bc4c89a | 2015-07-07 05:45:35 | [diff] [blame] | 1184 | { |
Eric Fiselier | fd83822 | 2016-12-23 23:37:52 | [diff] [blame] | 1185 | // FIXME: Add debug mode checking for the iterator input |
Eric Fiselier | 87c4104 | 2016-04-18 06:51:33 | [diff] [blame] | 1186 | return insert_or_assign(_VSTD::move(__k), _VSTD::forward<_Vp>(__v)).first; |
Marshall Clow | bc4c89a | 2015-07-07 05:45:35 | [diff] [blame] | 1187 | } |
Eric Fiselier | 6a470bc | 2017-04-18 22:50:56 | [diff] [blame] | 1188 | #endif // _LIBCPP_STD_VER > 14 |
Marshall Clow | bc4c89a | 2015-07-07 05:45:35 | [diff] [blame] | 1189 | |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1190 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1191 | iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1192 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | ec39296 | 2015-05-10 13:35:00 | [diff] [blame] | 1193 | iterator erase(iterator __p) {return __table_.erase(__p.__i_);} |
| 1194 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1195 | size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1196 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1197 | iterator erase(const_iterator __first, const_iterator __last) |
| 1198 | {return __table_.erase(__first.__i_, __last.__i_);} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1199 | _LIBCPP_INLINE_VISIBILITY |
Erik Pilkington | b0386a5 | 2018-08-01 01:33:38 | [diff] [blame] | 1200 | void clear() _NOEXCEPT {__table_.clear();} |
| 1201 | |
| 1202 | #if _LIBCPP_STD_VER > 14 |
| 1203 | _LIBCPP_INLINE_VISIBILITY |
| 1204 | insert_return_type insert(node_type&& __nh) |
| 1205 | { |
| 1206 | _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(), |
| 1207 | "node_type with incompatible allocator passed to unordered_map::insert()"); |
| 1208 | return __table_.template __node_handle_insert_unique< |
| 1209 | node_type, insert_return_type>(_VSTD::move(__nh)); |
| 1210 | } |
| 1211 | _LIBCPP_INLINE_VISIBILITY |
| 1212 | iterator insert(const_iterator __hint, node_type&& __nh) |
| 1213 | { |
| 1214 | _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(), |
| 1215 | "node_type with incompatible allocator passed to unordered_map::insert()"); |
| 1216 | return __table_.template __node_handle_insert_unique<node_type>( |
| 1217 | __hint.__i_, _VSTD::move(__nh)); |
| 1218 | } |
| 1219 | _LIBCPP_INLINE_VISIBILITY |
| 1220 | node_type extract(key_type const& __key) |
| 1221 | { |
| 1222 | return __table_.template __node_handle_extract<node_type>(__key); |
| 1223 | } |
| 1224 | _LIBCPP_INLINE_VISIBILITY |
| 1225 | node_type extract(const_iterator __it) |
| 1226 | { |
| 1227 | return __table_.template __node_handle_extract<node_type>( |
| 1228 | __it.__i_); |
| 1229 | } |
Erik Pilkington | 5c4e07a | 2018-10-31 17:31:35 | [diff] [blame] | 1230 | |
| 1231 | template <class _H2, class _P2> |
| 1232 | _LIBCPP_INLINE_VISIBILITY |
| 1233 | void merge(unordered_map<key_type, mapped_type, _H2, _P2, allocator_type>& __source) |
| 1234 | { |
| 1235 | _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), |
| 1236 | "merging container with incompatible allocator"); |
| 1237 | return __table_.__node_handle_merge_unique(__source.__table_); |
| 1238 | } |
| 1239 | template <class _H2, class _P2> |
| 1240 | _LIBCPP_INLINE_VISIBILITY |
| 1241 | void merge(unordered_map<key_type, mapped_type, _H2, _P2, allocator_type>&& __source) |
| 1242 | { |
| 1243 | _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), |
| 1244 | "merging container with incompatible allocator"); |
| 1245 | return __table_.__node_handle_merge_unique(__source.__table_); |
| 1246 | } |
| 1247 | template <class _H2, class _P2> |
| 1248 | _LIBCPP_INLINE_VISIBILITY |
| 1249 | void merge(unordered_multimap<key_type, mapped_type, _H2, _P2, allocator_type>& __source) |
| 1250 | { |
| 1251 | _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), |
| 1252 | "merging container with incompatible allocator"); |
| 1253 | return __table_.__node_handle_merge_unique(__source.__table_); |
| 1254 | } |
| 1255 | template <class _H2, class _P2> |
| 1256 | _LIBCPP_INLINE_VISIBILITY |
| 1257 | void merge(unordered_multimap<key_type, mapped_type, _H2, _P2, allocator_type>&& __source) |
| 1258 | { |
| 1259 | _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), |
| 1260 | "merging container with incompatible allocator"); |
| 1261 | return __table_.__node_handle_merge_unique(__source.__table_); |
| 1262 | } |
Erik Pilkington | b0386a5 | 2018-08-01 01:33:38 | [diff] [blame] | 1263 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1264 | |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1265 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 1266 | void swap(unordered_map& __u) |
| 1267 | _NOEXCEPT_(__is_nothrow_swappable<__table>::value) |
Eric Fiselier | 780b51d | 2016-12-28 05:53:01 | [diff] [blame] | 1268 | { __table_.swap(__u.__table_);} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1269 | |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1270 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1271 | hasher hash_function() const |
| 1272 | {return __table_.hash_function().hash_function();} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1273 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1274 | key_equal key_eq() const |
| 1275 | {return __table_.key_eq().key_eq();} |
| 1276 | |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1277 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1278 | iterator find(const key_type& __k) {return __table_.find(__k);} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1279 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1280 | const_iterator find(const key_type& __k) const {return __table_.find(__k);} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1281 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1282 | size_type count(const key_type& __k) const {return __table_.__count_unique(__k);} |
Zoe Carver | a17b1ae | 2019-07-16 03:21:01 | [diff] [blame] | 1283 | #if _LIBCPP_STD_VER > 17 |
| 1284 | _LIBCPP_INLINE_VISIBILITY |
| 1285 | bool contains(const key_type& __k) const {return find(__k) != end();} |
| 1286 | #endif // _LIBCPP_STD_VER > 17 |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1287 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1288 | pair<iterator, iterator> equal_range(const key_type& __k) |
| 1289 | {return __table_.__equal_range_unique(__k);} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1290 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1291 | pair<const_iterator, const_iterator> equal_range(const key_type& __k) const |
| 1292 | {return __table_.__equal_range_unique(__k);} |
| 1293 | |
| 1294 | mapped_type& operator[](const key_type& __k); |
Eric Fiselier | 0f90567 | 2016-02-11 21:45:53 | [diff] [blame] | 1295 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1296 | mapped_type& operator[](key_type&& __k); |
| 1297 | #endif |
| 1298 | |
| 1299 | mapped_type& at(const key_type& __k); |
| 1300 | const mapped_type& at(const key_type& __k) const; |
| 1301 | |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1302 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 1303 | size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1304 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 1305 | size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1306 | |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1307 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1308 | size_type bucket_size(size_type __n) const |
| 1309 | {return __table_.bucket_size(__n);} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1310 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1311 | size_type bucket(const key_type& __k) const {return __table_.bucket(__k);} |
| 1312 | |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1313 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1314 | local_iterator begin(size_type __n) {return __table_.begin(__n);} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1315 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1316 | local_iterator end(size_type __n) {return __table_.end(__n);} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1317 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1318 | const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1319 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1320 | const_local_iterator end(size_type __n) const {return __table_.cend(__n);} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1321 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1322 | const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1323 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1324 | const_local_iterator cend(size_type __n) const {return __table_.cend(__n);} |
| 1325 | |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1326 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 1327 | float load_factor() const _NOEXCEPT {return __table_.load_factor();} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1328 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 1329 | float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1330 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1331 | void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1332 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1333 | void rehash(size_type __n) {__table_.rehash(__n);} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1334 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1335 | void reserve(size_type __n) {__table_.reserve(__n);} |
| 1336 | |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 | [diff] [blame] | 1337 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1338 | |
| 1339 | bool __dereferenceable(const const_iterator* __i) const |
| 1340 | {return __table_.__dereferenceable(&__i->__i_);} |
| 1341 | bool __decrementable(const const_iterator* __i) const |
| 1342 | {return __table_.__decrementable(&__i->__i_);} |
| 1343 | bool __addable(const const_iterator* __i, ptrdiff_t __n) const |
| 1344 | {return __table_.__addable(&__i->__i_, __n);} |
| 1345 | bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const |
| 1346 | {return __table_.__addable(&__i->__i_, __n);} |
| 1347 | |
| 1348 | #endif // _LIBCPP_DEBUG_LEVEL >= 2 |
| 1349 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1350 | private: |
Eric Fiselier | 0f90567 | 2016-02-11 21:45:53 | [diff] [blame] | 1351 | |
| 1352 | #ifdef _LIBCPP_CXX03_LANG |
Howard Hinnant | 4a95f9e | 2013-07-04 20:59:16 | [diff] [blame] | 1353 | __node_holder __construct_node_with_key(const key_type& __k); |
Eric Fiselier | 0f90567 | 2016-02-11 21:45:53 | [diff] [blame] | 1354 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1355 | }; |
| 1356 | |
Louis Dionne | dfcd438 | 2019-07-15 20:06:01 | [diff] [blame] | 1357 | #ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES |
| 1358 | template<class _InputIterator, |
| 1359 | class _Hash = hash<__iter_key_type<_InputIterator>>, |
| 1360 | class _Pred = equal_to<__iter_key_type<_InputIterator>>, |
| 1361 | class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>, |
| 1362 | class = _EnableIf<!__is_allocator<_Hash>::value>, |
| 1363 | class = _EnableIf<!is_integral<_Hash>::value>, |
| 1364 | class = _EnableIf<!__is_allocator<_Pred>::value>, |
| 1365 | class = _EnableIf<__is_allocator<_Allocator>::value>> |
| 1366 | unordered_map(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type = 0, |
| 1367 | _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator()) |
| 1368 | -> unordered_map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Hash, _Pred, _Allocator>; |
| 1369 | |
| 1370 | template<class _Key, class _Tp, class _Hash = hash<remove_const_t<_Key>>, |
| 1371 | class _Pred = equal_to<remove_const_t<_Key>>, |
| 1372 | class _Allocator = allocator<pair<const _Key, _Tp>>, |
| 1373 | class = _EnableIf<!__is_allocator<_Hash>::value>, |
| 1374 | class = _EnableIf<!is_integral<_Hash>::value>, |
| 1375 | class = _EnableIf<!__is_allocator<_Pred>::value>, |
| 1376 | class = _EnableIf<__is_allocator<_Allocator>::value>> |
| 1377 | unordered_map(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type = 0, |
| 1378 | _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator()) |
| 1379 | -> unordered_map<remove_const_t<_Key>, _Tp, _Hash, _Pred, _Allocator>; |
| 1380 | |
| 1381 | template<class _InputIterator, class _Allocator, |
| 1382 | class = _EnableIf<__is_allocator<_Allocator>::value>> |
| 1383 | unordered_map(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Allocator) |
| 1384 | -> unordered_map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, |
| 1385 | hash<__iter_key_type<_InputIterator>>, equal_to<__iter_key_type<_InputIterator>>, _Allocator>; |
| 1386 | |
| 1387 | template<class _InputIterator, class _Allocator, |
| 1388 | class = _EnableIf<__is_allocator<_Allocator>::value>> |
| 1389 | unordered_map(_InputIterator, _InputIterator, _Allocator) |
| 1390 | -> unordered_map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, |
| 1391 | hash<__iter_key_type<_InputIterator>>, equal_to<__iter_key_type<_InputIterator>>, _Allocator>; |
| 1392 | |
| 1393 | template<class _InputIterator, class _Hash, class _Allocator, |
| 1394 | class = _EnableIf<!__is_allocator<_Hash>::value>, |
| 1395 | class = _EnableIf<!is_integral<_Hash>::value>, |
| 1396 | class = _EnableIf<__is_allocator<_Allocator>::value>> |
| 1397 | unordered_map(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator) |
| 1398 | -> unordered_map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, |
| 1399 | _Hash, equal_to<__iter_key_type<_InputIterator>>, _Allocator>; |
| 1400 | |
| 1401 | template<class _Key, class _Tp, class _Allocator, |
| 1402 | class = _EnableIf<__is_allocator<_Allocator>::value>> |
| 1403 | unordered_map(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type, _Allocator) |
| 1404 | -> unordered_map<remove_const_t<_Key>, _Tp, |
| 1405 | hash<remove_const_t<_Key>>, |
| 1406 | equal_to<remove_const_t<_Key>>, _Allocator>; |
| 1407 | |
| 1408 | template<class _Key, class _Tp, class _Allocator, |
| 1409 | class = _EnableIf<__is_allocator<_Allocator>::value>> |
| 1410 | unordered_map(initializer_list<pair<_Key, _Tp>>, _Allocator) |
| 1411 | -> unordered_map<remove_const_t<_Key>, _Tp, |
| 1412 | hash<remove_const_t<_Key>>, |
| 1413 | equal_to<remove_const_t<_Key>>, _Allocator>; |
| 1414 | |
| 1415 | template<class _Key, class _Tp, class _Hash, class _Allocator, |
| 1416 | class = _EnableIf<!__is_allocator<_Hash>::value>, |
| 1417 | class = _EnableIf<!is_integral<_Hash>::value>, |
| 1418 | class = _EnableIf<__is_allocator<_Allocator>::value>> |
| 1419 | unordered_map(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator) |
| 1420 | -> unordered_map<remove_const_t<_Key>, _Tp, _Hash, |
| 1421 | equal_to<remove_const_t<_Key>>, _Allocator>; |
| 1422 | #endif |
| 1423 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1424 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1425 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 1426 | size_type __n, const hasher& __hf, const key_equal& __eql) |
| 1427 | : __table_(__hf, __eql) |
| 1428 | { |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 | [diff] [blame] | 1429 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1430 | __get_db()->__insert_c(this); |
| 1431 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1432 | __table_.rehash(__n); |
| 1433 | } |
| 1434 | |
| 1435 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1436 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 1437 | size_type __n, const hasher& __hf, const key_equal& __eql, |
| 1438 | const allocator_type& __a) |
Marshall Clow | 2a10c96 | 2016-08-17 05:58:40 | [diff] [blame] | 1439 | : __table_(__hf, __eql, typename __table::allocator_type(__a)) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1440 | { |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 | [diff] [blame] | 1441 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1442 | __get_db()->__insert_c(this); |
| 1443 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1444 | __table_.rehash(__n); |
| 1445 | } |
| 1446 | |
| 1447 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 | [diff] [blame] | 1448 | inline |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1449 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 1450 | const allocator_type& __a) |
Marshall Clow | 2a10c96 | 2016-08-17 05:58:40 | [diff] [blame] | 1451 | : __table_(typename __table::allocator_type(__a)) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1452 | { |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 | [diff] [blame] | 1453 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1454 | __get_db()->__insert_c(this); |
| 1455 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1456 | } |
| 1457 | |
| 1458 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1459 | template <class _InputIterator> |
| 1460 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 1461 | _InputIterator __first, _InputIterator __last) |
| 1462 | { |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 | [diff] [blame] | 1463 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1464 | __get_db()->__insert_c(this); |
| 1465 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1466 | insert(__first, __last); |
| 1467 | } |
| 1468 | |
| 1469 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1470 | template <class _InputIterator> |
| 1471 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 1472 | _InputIterator __first, _InputIterator __last, size_type __n, |
| 1473 | const hasher& __hf, const key_equal& __eql) |
| 1474 | : __table_(__hf, __eql) |
| 1475 | { |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 | [diff] [blame] | 1476 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1477 | __get_db()->__insert_c(this); |
| 1478 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1479 | __table_.rehash(__n); |
| 1480 | insert(__first, __last); |
| 1481 | } |
| 1482 | |
| 1483 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1484 | template <class _InputIterator> |
| 1485 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 1486 | _InputIterator __first, _InputIterator __last, size_type __n, |
| 1487 | const hasher& __hf, const key_equal& __eql, const allocator_type& __a) |
Marshall Clow | 2a10c96 | 2016-08-17 05:58:40 | [diff] [blame] | 1488 | : __table_(__hf, __eql, typename __table::allocator_type(__a)) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1489 | { |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 | [diff] [blame] | 1490 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1491 | __get_db()->__insert_c(this); |
| 1492 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1493 | __table_.rehash(__n); |
| 1494 | insert(__first, __last); |
| 1495 | } |
| 1496 | |
| 1497 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1498 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 1499 | const unordered_map& __u) |
| 1500 | : __table_(__u.__table_) |
| 1501 | { |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 | [diff] [blame] | 1502 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1503 | __get_db()->__insert_c(this); |
| 1504 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1505 | __table_.rehash(__u.bucket_count()); |
| 1506 | insert(__u.begin(), __u.end()); |
| 1507 | } |
| 1508 | |
| 1509 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1510 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 1511 | const unordered_map& __u, const allocator_type& __a) |
Marshall Clow | 2a10c96 | 2016-08-17 05:58:40 | [diff] [blame] | 1512 | : __table_(__u.__table_, typename __table::allocator_type(__a)) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1513 | { |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 | [diff] [blame] | 1514 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1515 | __get_db()->__insert_c(this); |
| 1516 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1517 | __table_.rehash(__u.bucket_count()); |
| 1518 | insert(__u.begin(), __u.end()); |
| 1519 | } |
| 1520 | |
Eric Fiselier | 6a470bc | 2017-04-18 22:50:56 | [diff] [blame] | 1521 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1522 | |
| 1523 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 | [diff] [blame] | 1524 | inline |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1525 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 1526 | unordered_map&& __u) |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 1527 | _NOEXCEPT_(is_nothrow_move_constructible<__table>::value) |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 1528 | : __table_(_VSTD::move(__u.__table_)) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1529 | { |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 | [diff] [blame] | 1530 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1531 | __get_db()->__insert_c(this); |
Howard Hinnant | 4c80bfb | 2013-07-30 21:04:42 | [diff] [blame] | 1532 | __get_db()->swap(this, &__u); |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 | [diff] [blame] | 1533 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1534 | } |
| 1535 | |
| 1536 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1537 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 1538 | unordered_map&& __u, const allocator_type& __a) |
Marshall Clow | 2a10c96 | 2016-08-17 05:58:40 | [diff] [blame] | 1539 | : __table_(_VSTD::move(__u.__table_), typename __table::allocator_type(__a)) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1540 | { |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 | [diff] [blame] | 1541 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1542 | __get_db()->__insert_c(this); |
| 1543 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1544 | if (__a != __u.get_allocator()) |
| 1545 | { |
| 1546 | iterator __i = __u.begin(); |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 | [diff] [blame] | 1547 | while (__u.size() != 0) { |
Erik Pilkington | f52318b | 2018-06-04 20:38:23 | [diff] [blame] | 1548 | __table_.__emplace_unique( |
| 1549 | __u.__table_.remove((__i++).__i_)->__value_.__move()); |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 | [diff] [blame] | 1550 | } |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1551 | } |
Howard Hinnant | 4c80bfb | 2013-07-30 21:04:42 | [diff] [blame] | 1552 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1553 | else |
| 1554 | __get_db()->swap(this, &__u); |
| 1555 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1556 | } |
| 1557 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1558 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1559 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 1560 | initializer_list<value_type> __il) |
| 1561 | { |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 | [diff] [blame] | 1562 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1563 | __get_db()->__insert_c(this); |
| 1564 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1565 | insert(__il.begin(), __il.end()); |
| 1566 | } |
| 1567 | |
| 1568 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1569 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 1570 | initializer_list<value_type> __il, size_type __n, const hasher& __hf, |
| 1571 | const key_equal& __eql) |
| 1572 | : __table_(__hf, __eql) |
| 1573 | { |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 | [diff] [blame] | 1574 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1575 | __get_db()->__insert_c(this); |
| 1576 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1577 | __table_.rehash(__n); |
| 1578 | insert(__il.begin(), __il.end()); |
| 1579 | } |
| 1580 | |
| 1581 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1582 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 1583 | initializer_list<value_type> __il, size_type __n, const hasher& __hf, |
| 1584 | const key_equal& __eql, const allocator_type& __a) |
Marshall Clow | 2a10c96 | 2016-08-17 05:58:40 | [diff] [blame] | 1585 | : __table_(__hf, __eql, typename __table::allocator_type(__a)) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1586 | { |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 | [diff] [blame] | 1587 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1588 | __get_db()->__insert_c(this); |
| 1589 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1590 | __table_.rehash(__n); |
| 1591 | insert(__il.begin(), __il.end()); |
| 1592 | } |
| 1593 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1594 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 | [diff] [blame] | 1595 | inline |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1596 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& |
| 1597 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_map&& __u) |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 1598 | _NOEXCEPT_(is_nothrow_move_assignable<__table>::value) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1599 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 1600 | __table_ = _VSTD::move(__u.__table_); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1601 | return *this; |
| 1602 | } |
| 1603 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1604 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 | [diff] [blame] | 1605 | inline |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1606 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& |
| 1607 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=( |
| 1608 | initializer_list<value_type> __il) |
| 1609 | { |
| 1610 | __table_.__assign_unique(__il.begin(), __il.end()); |
| 1611 | return *this; |
| 1612 | } |
| 1613 | |
Eric Fiselier | 6a470bc | 2017-04-18 22:50:56 | [diff] [blame] | 1614 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1615 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1616 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1617 | template <class _InputIterator> |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 | [diff] [blame] | 1618 | inline |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1619 | void |
| 1620 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, |
| 1621 | _InputIterator __last) |
| 1622 | { |
| 1623 | for (; __first != __last; ++__first) |
| 1624 | __table_.__insert_unique(*__first); |
| 1625 | } |
| 1626 | |
Eric Fiselier | 6a470bc | 2017-04-18 22:50:56 | [diff] [blame] | 1627 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1628 | |
Eric Fiselier | 0f90567 | 2016-02-11 21:45:53 | [diff] [blame] | 1629 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1630 | _Tp& |
| 1631 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k) |
| 1632 | { |
| 1633 | return __table_.__emplace_unique_key_args(__k, |
| 1634 | std::piecewise_construct, std::forward_as_tuple(__k), |
Erik Pilkington | f52318b | 2018-06-04 20:38:23 | [diff] [blame] | 1635 | std::forward_as_tuple()).first->__get_value().second; |
Eric Fiselier | 0f90567 | 2016-02-11 21:45:53 | [diff] [blame] | 1636 | } |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1637 | |
| 1638 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1639 | _Tp& |
| 1640 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](key_type&& __k) |
| 1641 | { |
Eric Fiselier | 0f90567 | 2016-02-11 21:45:53 | [diff] [blame] | 1642 | return __table_.__emplace_unique_key_args(__k, |
| 1643 | std::piecewise_construct, std::forward_as_tuple(std::move(__k)), |
Erik Pilkington | f52318b | 2018-06-04 20:38:23 | [diff] [blame] | 1644 | std::forward_as_tuple()).first->__get_value().second; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1645 | } |
Eric Fiselier | 6a470bc | 2017-04-18 22:50:56 | [diff] [blame] | 1646 | #else // _LIBCPP_CXX03_LANG |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1647 | |
Eric Fiselier | 6a470bc | 2017-04-18 22:50:56 | [diff] [blame] | 1648 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1649 | typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder |
| 1650 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node_with_key(const key_type& __k) |
| 1651 | { |
| 1652 | __node_allocator& __na = __table_.__node_alloc(); |
| 1653 | __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); |
Erik Pilkington | f52318b | 2018-06-04 20:38:23 | [diff] [blame] | 1654 | __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().first), __k); |
Eric Fiselier | 6a470bc | 2017-04-18 22:50:56 | [diff] [blame] | 1655 | __h.get_deleter().__first_constructed = true; |
Erik Pilkington | f52318b | 2018-06-04 20:38:23 | [diff] [blame] | 1656 | __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().second)); |
Eric Fiselier | 6a470bc | 2017-04-18 22:50:56 | [diff] [blame] | 1657 | __h.get_deleter().__second_constructed = true; |
| 1658 | return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03 |
| 1659 | } |
| 1660 | |
| 1661 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1662 | _Tp& |
| 1663 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k) |
| 1664 | { |
| 1665 | iterator __i = find(__k); |
| 1666 | if (__i != end()) |
| 1667 | return __i->second; |
| 1668 | __node_holder __h = __construct_node_with_key(__k); |
| 1669 | pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get()); |
| 1670 | __h.release(); |
| 1671 | return __r.first->second; |
| 1672 | } |
| 1673 | |
| 1674 | #endif // _LIBCPP_CXX03_MODE |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1675 | |
| 1676 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1677 | _Tp& |
| 1678 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k) |
| 1679 | { |
| 1680 | iterator __i = find(__k); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1681 | if (__i == end()) |
Louis Dionne | 7232a84 | 2019-02-12 16:06:02 | [diff] [blame] | 1682 | __throw_out_of_range("unordered_map::at: key not found"); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1683 | return __i->second; |
| 1684 | } |
| 1685 | |
| 1686 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1687 | const _Tp& |
| 1688 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k) const |
| 1689 | { |
| 1690 | const_iterator __i = find(__k); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1691 | if (__i == end()) |
Louis Dionne | 7232a84 | 2019-02-12 16:06:02 | [diff] [blame] | 1692 | __throw_out_of_range("unordered_map::at: key not found"); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1693 | return __i->second; |
| 1694 | } |
| 1695 | |
| 1696 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1697 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1698 | void |
| 1699 | swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, |
| 1700 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 1701 | _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1702 | { |
| 1703 | __x.swap(__y); |
| 1704 | } |
| 1705 | |
Marshall Clow | f60c63c0 | 2018-12-14 18:49:35 | [diff] [blame] | 1706 | #if _LIBCPP_STD_VER > 17 |
| 1707 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc, class _Predicate> |
| 1708 | inline _LIBCPP_INLINE_VISIBILITY |
| 1709 | void erase_if(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __c, _Predicate __pred) |
| 1710 | { __libcpp_erase_if_container(__c, __pred); } |
| 1711 | #endif |
| 1712 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1713 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1714 | bool |
| 1715 | operator==(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, |
| 1716 | const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) |
| 1717 | { |
| 1718 | if (__x.size() != __y.size()) |
| 1719 | return false; |
| 1720 | typedef typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator |
| 1721 | const_iterator; |
| 1722 | for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end(); |
| 1723 | __i != __ex; ++__i) |
| 1724 | { |
| 1725 | const_iterator __j = __y.find(__i->first); |
| 1726 | if (__j == __ey || !(*__i == *__j)) |
| 1727 | return false; |
| 1728 | } |
| 1729 | return true; |
| 1730 | } |
| 1731 | |
| 1732 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1733 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1734 | bool |
| 1735 | operator!=(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, |
| 1736 | const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) |
| 1737 | { |
| 1738 | return !(__x == __y); |
| 1739 | } |
| 1740 | |
| 1741 | template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>, |
| 1742 | class _Alloc = allocator<pair<const _Key, _Tp> > > |
Eric Fiselier | e2f2d1ed | 2017-01-04 23:56:00 | [diff] [blame] | 1743 | class _LIBCPP_TEMPLATE_VIS unordered_multimap |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1744 | { |
| 1745 | public: |
| 1746 | // types |
| 1747 | typedef _Key key_type; |
| 1748 | typedef _Tp mapped_type; |
Louis Dionne | dfcd438 | 2019-07-15 20:06:01 | [diff] [blame] | 1749 | typedef typename __identity<_Hash>::type hasher; |
| 1750 | typedef typename __identity<_Pred>::type key_equal; |
| 1751 | typedef typename __identity<_Alloc>::type allocator_type; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1752 | typedef pair<const key_type, mapped_type> value_type; |
| 1753 | typedef value_type& reference; |
| 1754 | typedef const value_type& const_reference; |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 | [diff] [blame] | 1755 | static_assert((is_same<value_type, typename allocator_type::value_type>::value), |
| 1756 | "Invalid allocator::value_type"); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1757 | |
| 1758 | private: |
Howard Hinnant | 9fd9f84 | 2013-09-30 19:08:22 | [diff] [blame] | 1759 | typedef __hash_value_type<key_type, mapped_type> __value_type; |
Howard Hinnant | abb160e | 2013-07-05 18:06:00 | [diff] [blame] | 1760 | typedef __unordered_map_hasher<key_type, __value_type, hasher> __hasher; |
| 1761 | typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal; |
Marshall Clow | 1f50801 | 2015-04-07 05:21:38 | [diff] [blame] | 1762 | typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>, |
| 1763 | __value_type>::type __allocator_type; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1764 | |
| 1765 | typedef __hash_table<__value_type, __hasher, |
| 1766 | __key_equal, __allocator_type> __table; |
| 1767 | |
| 1768 | __table __table_; |
| 1769 | |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 | [diff] [blame] | 1770 | typedef typename __table::_NodeTypes _NodeTypes; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1771 | typedef typename __table::__node_traits __node_traits; |
| 1772 | typedef typename __table::__node_allocator __node_allocator; |
| 1773 | typedef typename __table::__node __node; |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 | [diff] [blame] | 1774 | typedef __hash_map_node_destructor<__node_allocator> _Dp; |
| 1775 | typedef unique_ptr<__node, _Dp> __node_holder; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1776 | typedef allocator_traits<allocator_type> __alloc_traits; |
Eric Fiselier | 75d0dcf | 2016-02-10 20:46:23 | [diff] [blame] | 1777 | static_assert((is_same<typename __node_traits::size_type, |
| 1778 | typename __alloc_traits::size_type>::value), |
| 1779 | "Allocator uses different size_type for different types"); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1780 | public: |
| 1781 | typedef typename __alloc_traits::pointer pointer; |
| 1782 | typedef typename __alloc_traits::const_pointer const_pointer; |
Eric Fiselier | 75d0dcf | 2016-02-10 20:46:23 | [diff] [blame] | 1783 | typedef typename __table::size_type size_type; |
| 1784 | typedef typename __table::difference_type difference_type; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1785 | |
| 1786 | typedef __hash_map_iterator<typename __table::iterator> iterator; |
| 1787 | typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator; |
| 1788 | typedef __hash_map_iterator<typename __table::local_iterator> local_iterator; |
| 1789 | typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator; |
| 1790 | |
Erik Pilkington | b0386a5 | 2018-08-01 01:33:38 | [diff] [blame] | 1791 | #if _LIBCPP_STD_VER > 14 |
| 1792 | typedef __map_node_handle<__node, allocator_type> node_type; |
| 1793 | #endif |
| 1794 | |
Erik Pilkington | 5c4e07a | 2018-10-31 17:31:35 | [diff] [blame] | 1795 | template <class _Key2, class _Tp2, class _Hash2, class _Pred2, class _Alloc2> |
| 1796 | friend class _LIBCPP_TEMPLATE_VIS unordered_map; |
| 1797 | template <class _Key2, class _Tp2, class _Hash2, class _Pred2, class _Alloc2> |
| 1798 | friend class _LIBCPP_TEMPLATE_VIS unordered_multimap; |
| 1799 | |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1800 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 1801 | unordered_multimap() |
| 1802 | _NOEXCEPT_(is_nothrow_default_constructible<__table>::value) |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 | [diff] [blame] | 1803 | { |
| 1804 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1805 | __get_db()->__insert_c(this); |
| 1806 | #endif |
| 1807 | } |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1808 | explicit unordered_multimap(size_type __n, const hasher& __hf = hasher(), |
| 1809 | const key_equal& __eql = key_equal()); |
| 1810 | unordered_multimap(size_type __n, const hasher& __hf, |
| 1811 | const key_equal& __eql, |
| 1812 | const allocator_type& __a); |
| 1813 | template <class _InputIterator> |
| 1814 | unordered_multimap(_InputIterator __first, _InputIterator __last); |
| 1815 | template <class _InputIterator> |
| 1816 | unordered_multimap(_InputIterator __first, _InputIterator __last, |
| 1817 | size_type __n, const hasher& __hf = hasher(), |
| 1818 | const key_equal& __eql = key_equal()); |
| 1819 | template <class _InputIterator> |
| 1820 | unordered_multimap(_InputIterator __first, _InputIterator __last, |
| 1821 | size_type __n, const hasher& __hf, |
| 1822 | const key_equal& __eql, |
| 1823 | const allocator_type& __a); |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 | [diff] [blame] | 1824 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1825 | explicit unordered_multimap(const allocator_type& __a); |
| 1826 | unordered_multimap(const unordered_multimap& __u); |
| 1827 | unordered_multimap(const unordered_multimap& __u, const allocator_type& __a); |
Eric Fiselier | 6a470bc | 2017-04-18 22:50:56 | [diff] [blame] | 1828 | #ifndef _LIBCPP_CXX03_LANG |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 | [diff] [blame] | 1829 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 1830 | unordered_multimap(unordered_multimap&& __u) |
| 1831 | _NOEXCEPT_(is_nothrow_move_constructible<__table>::value); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1832 | unordered_multimap(unordered_multimap&& __u, const allocator_type& __a); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1833 | unordered_multimap(initializer_list<value_type> __il); |
| 1834 | unordered_multimap(initializer_list<value_type> __il, size_type __n, |
| 1835 | const hasher& __hf = hasher(), |
| 1836 | const key_equal& __eql = key_equal()); |
| 1837 | unordered_multimap(initializer_list<value_type> __il, size_type __n, |
| 1838 | const hasher& __hf, const key_equal& __eql, |
| 1839 | const allocator_type& __a); |
Eric Fiselier | 6a470bc | 2017-04-18 22:50:56 | [diff] [blame] | 1840 | #endif // _LIBCPP_CXX03_LANG |
Marshall Clow | 3cd37e6 | 2013-09-12 03:00:31 | [diff] [blame] | 1841 | #if _LIBCPP_STD_VER > 11 |
| 1842 | _LIBCPP_INLINE_VISIBILITY |
| 1843 | unordered_multimap(size_type __n, const allocator_type& __a) |
| 1844 | : unordered_multimap(__n, hasher(), key_equal(), __a) {} |
| 1845 | _LIBCPP_INLINE_VISIBILITY |
| 1846 | unordered_multimap(size_type __n, const hasher& __hf, const allocator_type& __a) |
| 1847 | : unordered_multimap(__n, __hf, key_equal(), __a) {} |
| 1848 | template <class _InputIterator> |
| 1849 | _LIBCPP_INLINE_VISIBILITY |
| 1850 | unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a) |
| 1851 | : unordered_multimap(__first, __last, __n, hasher(), key_equal(), __a) {} |
| 1852 | template <class _InputIterator> |
| 1853 | _LIBCPP_INLINE_VISIBILITY |
Louis Dionne | a2a1ec2 | 2019-05-29 16:01:36 | [diff] [blame] | 1854 | unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf, |
Marshall Clow | 3cd37e6 | 2013-09-12 03:00:31 | [diff] [blame] | 1855 | const allocator_type& __a) |
| 1856 | : unordered_multimap(__first, __last, __n, __hf, key_equal(), __a) {} |
| 1857 | _LIBCPP_INLINE_VISIBILITY |
| 1858 | unordered_multimap(initializer_list<value_type> __il, size_type __n, const allocator_type& __a) |
| 1859 | : unordered_multimap(__il, __n, hasher(), key_equal(), __a) {} |
| 1860 | _LIBCPP_INLINE_VISIBILITY |
Louis Dionne | a2a1ec2 | 2019-05-29 16:01:36 | [diff] [blame] | 1861 | unordered_multimap(initializer_list<value_type> __il, size_type __n, const hasher& __hf, |
Marshall Clow | 3cd37e6 | 2013-09-12 03:00:31 | [diff] [blame] | 1862 | const allocator_type& __a) |
| 1863 | : unordered_multimap(__il, __n, __hf, key_equal(), __a) {} |
| 1864 | #endif |
Louis Dionne | 7c142fc | 2019-04-11 16:14:56 | [diff] [blame] | 1865 | _LIBCPP_INLINE_VISIBILITY |
| 1866 | ~unordered_multimap() { |
| 1867 | static_assert(sizeof(__diagnose_unordered_container_requirements<_Key, _Hash, _Pred>(0)), ""); |
| 1868 | } |
| 1869 | |
Howard Hinnant | 5a33687 | 2011-07-01 19:24:36 | [diff] [blame] | 1870 | _LIBCPP_INLINE_VISIBILITY |
| 1871 | unordered_multimap& operator=(const unordered_multimap& __u) |
| 1872 | { |
Marshall Clow | 2ee8372 | 2016-07-18 13:19:00 | [diff] [blame] | 1873 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 5a33687 | 2011-07-01 19:24:36 | [diff] [blame] | 1874 | __table_ = __u.__table_; |
Howard Hinnant | 307f814 | 2013-06-22 15:21:29 | [diff] [blame] | 1875 | #else |
Marshall Clow | 74cf6ff | 2014-02-08 04:03:14 | [diff] [blame] | 1876 | if (this != &__u) { |
| 1877 | __table_.clear(); |
| 1878 | __table_.hash_function() = __u.__table_.hash_function(); |
| 1879 | __table_.key_eq() = __u.__table_.key_eq(); |
| 1880 | __table_.max_load_factor() = __u.__table_.max_load_factor(); |
| 1881 | __table_.__copy_assign_alloc(__u.__table_); |
| 1882 | insert(__u.begin(), __u.end()); |
| 1883 | } |
Howard Hinnant | 307f814 | 2013-06-22 15:21:29 | [diff] [blame] | 1884 | #endif |
Howard Hinnant | 5a33687 | 2011-07-01 19:24:36 | [diff] [blame] | 1885 | return *this; |
| 1886 | } |
Eric Fiselier | 6a470bc | 2017-04-18 22:50:56 | [diff] [blame] | 1887 | #ifndef _LIBCPP_CXX03_LANG |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 | [diff] [blame] | 1888 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 1889 | unordered_multimap& operator=(unordered_multimap&& __u) |
| 1890 | _NOEXCEPT_(is_nothrow_move_assignable<__table>::value); |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 | [diff] [blame] | 1891 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1892 | unordered_multimap& operator=(initializer_list<value_type> __il); |
Eric Fiselier | 6a470bc | 2017-04-18 22:50:56 | [diff] [blame] | 1893 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1894 | |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1895 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 1896 | allocator_type get_allocator() const _NOEXCEPT |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1897 | {return allocator_type(__table_.__node_alloc());} |
| 1898 | |
Marshall Clow | 72c8fad | 2017-11-15 05:51:26 | [diff] [blame] | 1899 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 1900 | bool empty() const _NOEXCEPT {return __table_.size() == 0;} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1901 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 1902 | size_type size() const _NOEXCEPT {return __table_.size();} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1903 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 1904 | size_type max_size() const _NOEXCEPT {return __table_.max_size();} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1905 | |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1906 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 1907 | iterator begin() _NOEXCEPT {return __table_.begin();} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1908 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 1909 | iterator end() _NOEXCEPT {return __table_.end();} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1910 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 1911 | const_iterator begin() const _NOEXCEPT {return __table_.begin();} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1912 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 1913 | const_iterator end() const _NOEXCEPT {return __table_.end();} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1914 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 1915 | const_iterator cbegin() const _NOEXCEPT {return __table_.begin();} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1916 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 1917 | const_iterator cend() const _NOEXCEPT {return __table_.end();} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1918 | |
Eric Fiselier | 7a9f500 | 2016-04-18 01:40:45 | [diff] [blame] | 1919 | _LIBCPP_INLINE_VISIBILITY |
| 1920 | iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);} |
| 1921 | |
| 1922 | _LIBCPP_INLINE_VISIBILITY |
| 1923 | iterator insert(const_iterator __p, const value_type& __x) |
| 1924 | {return __table_.__insert_multi(__p.__i_, __x);} |
| 1925 | |
| 1926 | template <class _InputIterator> |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 | [diff] [blame] | 1927 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 7a9f500 | 2016-04-18 01:40:45 | [diff] [blame] | 1928 | void insert(_InputIterator __first, _InputIterator __last); |
| 1929 | |
Eric Fiselier | 6a470bc | 2017-04-18 22:50:56 | [diff] [blame] | 1930 | #ifndef _LIBCPP_CXX03_LANG |
Eric Fiselier | 7a9f500 | 2016-04-18 01:40:45 | [diff] [blame] | 1931 | _LIBCPP_INLINE_VISIBILITY |
| 1932 | void insert(initializer_list<value_type> __il) |
| 1933 | {insert(__il.begin(), __il.end());} |
Eric Fiselier | 7a9f500 | 2016-04-18 01:40:45 | [diff] [blame] | 1934 | _LIBCPP_INLINE_VISIBILITY |
| 1935 | iterator insert(value_type&& __x) {return __table_.__insert_multi(_VSTD::move(__x));} |
| 1936 | |
| 1937 | _LIBCPP_INLINE_VISIBILITY |
| 1938 | iterator insert(const_iterator __p, value_type&& __x) |
| 1939 | {return __table_.__insert_multi(__p.__i_, _VSTD::move(__x));} |
| 1940 | |
| 1941 | template <class _Pp, |
| 1942 | class = typename enable_if<is_constructible<value_type, _Pp>::value>::type> |
| 1943 | _LIBCPP_INLINE_VISIBILITY |
| 1944 | iterator insert(_Pp&& __x) |
| 1945 | {return __table_.__insert_multi(_VSTD::forward<_Pp>(__x));} |
| 1946 | |
| 1947 | template <class _Pp, |
| 1948 | class = typename enable_if<is_constructible<value_type, _Pp>::value>::type> |
| 1949 | _LIBCPP_INLINE_VISIBILITY |
| 1950 | iterator insert(const_iterator __p, _Pp&& __x) |
| 1951 | {return __table_.__insert_multi(__p.__i_, _VSTD::forward<_Pp>(__x));} |
| 1952 | |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 | [diff] [blame] | 1953 | template <class... _Args> |
| 1954 | iterator emplace(_Args&&... __args) { |
| 1955 | return __table_.__emplace_multi(_VSTD::forward<_Args>(__args)...); |
| 1956 | } |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 | [diff] [blame] | 1957 | |
Howard Hinnant | 8b805c9 | 2012-05-25 22:04:21 | [diff] [blame] | 1958 | template <class... _Args> |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 | [diff] [blame] | 1959 | iterator emplace_hint(const_iterator __p, _Args&&... __args) { |
| 1960 | return __table_.__emplace_hint_multi(__p.__i_, _VSTD::forward<_Args>(__args)...); |
| 1961 | } |
| 1962 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1963 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1964 | |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1965 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1966 | iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1967 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | ec39296 | 2015-05-10 13:35:00 | [diff] [blame] | 1968 | iterator erase(iterator __p) {return __table_.erase(__p.__i_);} |
| 1969 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1970 | size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1971 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1972 | iterator erase(const_iterator __first, const_iterator __last) |
| 1973 | {return __table_.erase(__first.__i_, __last.__i_);} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 1974 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 1975 | void clear() _NOEXCEPT {__table_.clear();} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1976 | |
Erik Pilkington | b0386a5 | 2018-08-01 01:33:38 | [diff] [blame] | 1977 | #if _LIBCPP_STD_VER > 14 |
| 1978 | _LIBCPP_INLINE_VISIBILITY |
| 1979 | iterator insert(node_type&& __nh) |
| 1980 | { |
| 1981 | _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(), |
| 1982 | "node_type with incompatible allocator passed to unordered_multimap::insert()"); |
| 1983 | return __table_.template __node_handle_insert_multi<node_type>( |
| 1984 | _VSTD::move(__nh)); |
| 1985 | } |
| 1986 | _LIBCPP_INLINE_VISIBILITY |
| 1987 | iterator insert(const_iterator __hint, node_type&& __nh) |
| 1988 | { |
| 1989 | _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(), |
| 1990 | "node_type with incompatible allocator passed to unordered_multimap::insert()"); |
| 1991 | return __table_.template __node_handle_insert_multi<node_type>( |
| 1992 | __hint.__i_, _VSTD::move(__nh)); |
| 1993 | } |
| 1994 | _LIBCPP_INLINE_VISIBILITY |
| 1995 | node_type extract(key_type const& __key) |
| 1996 | { |
| 1997 | return __table_.template __node_handle_extract<node_type>(__key); |
| 1998 | } |
| 1999 | _LIBCPP_INLINE_VISIBILITY |
| 2000 | node_type extract(const_iterator __it) |
| 2001 | { |
| 2002 | return __table_.template __node_handle_extract<node_type>( |
| 2003 | __it.__i_); |
| 2004 | } |
Erik Pilkington | 5c4e07a | 2018-10-31 17:31:35 | [diff] [blame] | 2005 | |
| 2006 | template <class _H2, class _P2> |
| 2007 | _LIBCPP_INLINE_VISIBILITY |
| 2008 | void merge(unordered_multimap<key_type, mapped_type, _H2, _P2, allocator_type>& __source) |
| 2009 | { |
| 2010 | _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), |
| 2011 | "merging container with incompatible allocator"); |
| 2012 | return __table_.__node_handle_merge_multi(__source.__table_); |
| 2013 | } |
| 2014 | template <class _H2, class _P2> |
| 2015 | _LIBCPP_INLINE_VISIBILITY |
| 2016 | void merge(unordered_multimap<key_type, mapped_type, _H2, _P2, allocator_type>&& __source) |
| 2017 | { |
| 2018 | _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), |
| 2019 | "merging container with incompatible allocator"); |
| 2020 | return __table_.__node_handle_merge_multi(__source.__table_); |
| 2021 | } |
| 2022 | template <class _H2, class _P2> |
| 2023 | _LIBCPP_INLINE_VISIBILITY |
| 2024 | void merge(unordered_map<key_type, mapped_type, _H2, _P2, allocator_type>& __source) |
| 2025 | { |
| 2026 | _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), |
| 2027 | "merging container with incompatible allocator"); |
| 2028 | return __table_.__node_handle_merge_multi(__source.__table_); |
| 2029 | } |
| 2030 | template <class _H2, class _P2> |
| 2031 | _LIBCPP_INLINE_VISIBILITY |
| 2032 | void merge(unordered_map<key_type, mapped_type, _H2, _P2, allocator_type>&& __source) |
| 2033 | { |
| 2034 | _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), |
| 2035 | "merging container with incompatible allocator"); |
| 2036 | return __table_.__node_handle_merge_multi(__source.__table_); |
| 2037 | } |
Erik Pilkington | b0386a5 | 2018-08-01 01:33:38 | [diff] [blame] | 2038 | #endif |
| 2039 | |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 2040 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 2041 | void swap(unordered_multimap& __u) |
| 2042 | _NOEXCEPT_(__is_nothrow_swappable<__table>::value) |
| 2043 | {__table_.swap(__u.__table_);} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2044 | |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 2045 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2046 | hasher hash_function() const |
| 2047 | {return __table_.hash_function().hash_function();} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 2048 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2049 | key_equal key_eq() const |
| 2050 | {return __table_.key_eq().key_eq();} |
| 2051 | |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 2052 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2053 | iterator find(const key_type& __k) {return __table_.find(__k);} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 2054 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2055 | const_iterator find(const key_type& __k) const {return __table_.find(__k);} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 2056 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2057 | size_type count(const key_type& __k) const {return __table_.__count_multi(__k);} |
Zoe Carver | a17b1ae | 2019-07-16 03:21:01 | [diff] [blame] | 2058 | #if _LIBCPP_STD_VER > 17 |
| 2059 | _LIBCPP_INLINE_VISIBILITY |
| 2060 | bool contains(const key_type& __k) const {return find(__k) != end();} |
| 2061 | #endif // _LIBCPP_STD_VER > 17 |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 2062 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2063 | pair<iterator, iterator> equal_range(const key_type& __k) |
| 2064 | {return __table_.__equal_range_multi(__k);} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 2065 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2066 | pair<const_iterator, const_iterator> equal_range(const key_type& __k) const |
| 2067 | {return __table_.__equal_range_multi(__k);} |
| 2068 | |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 2069 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 2070 | size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 2071 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 2072 | size_type max_bucket_count() const _NOEXCEPT |
| 2073 | {return __table_.max_bucket_count();} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2074 | |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 2075 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2076 | size_type bucket_size(size_type __n) const |
| 2077 | {return __table_.bucket_size(__n);} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 2078 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2079 | size_type bucket(const key_type& __k) const {return __table_.bucket(__k);} |
| 2080 | |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 2081 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2082 | local_iterator begin(size_type __n) {return __table_.begin(__n);} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 2083 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2084 | local_iterator end(size_type __n) {return __table_.end(__n);} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 2085 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2086 | const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 2087 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2088 | const_local_iterator end(size_type __n) const {return __table_.cend(__n);} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 2089 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2090 | const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 2091 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2092 | const_local_iterator cend(size_type __n) const {return __table_.cend(__n);} |
| 2093 | |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 2094 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 2095 | float load_factor() const _NOEXCEPT {return __table_.load_factor();} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 2096 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 2097 | float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 2098 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2099 | void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 2100 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2101 | void rehash(size_type __n) {__table_.rehash(__n);} |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 2102 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2103 | void reserve(size_type __n) {__table_.reserve(__n);} |
| 2104 | |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 | [diff] [blame] | 2105 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2106 | |
| 2107 | bool __dereferenceable(const const_iterator* __i) const |
| 2108 | {return __table_.__dereferenceable(&__i->__i_);} |
| 2109 | bool __decrementable(const const_iterator* __i) const |
| 2110 | {return __table_.__decrementable(&__i->__i_);} |
| 2111 | bool __addable(const const_iterator* __i, ptrdiff_t __n) const |
| 2112 | {return __table_.__addable(&__i->__i_, __n);} |
| 2113 | bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const |
| 2114 | {return __table_.__addable(&__i->__i_, __n);} |
| 2115 | |
| 2116 | #endif // _LIBCPP_DEBUG_LEVEL >= 2 |
| 2117 | |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 | [diff] [blame] | 2118 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2119 | }; |
| 2120 | |
Louis Dionne | dfcd438 | 2019-07-15 20:06:01 | [diff] [blame] | 2121 | #ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES |
| 2122 | template<class _InputIterator, |
| 2123 | class _Hash = hash<__iter_key_type<_InputIterator>>, |
| 2124 | class _Pred = equal_to<__iter_key_type<_InputIterator>>, |
| 2125 | class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>, |
| 2126 | class = _EnableIf<!__is_allocator<_Hash>::value>, |
| 2127 | class = _EnableIf<!is_integral<_Hash>::value>, |
| 2128 | class = _EnableIf<!__is_allocator<_Pred>::value>, |
| 2129 | class = _EnableIf<__is_allocator<_Allocator>::value>> |
| 2130 | unordered_multimap(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type = 0, |
| 2131 | _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator()) |
| 2132 | -> unordered_multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Hash, _Pred, _Allocator>; |
| 2133 | |
| 2134 | template<class _Key, class _Tp, class _Hash = hash<remove_const_t<_Key>>, |
| 2135 | class _Pred = equal_to<remove_const_t<_Key>>, |
| 2136 | class _Allocator = allocator<pair<const _Key, _Tp>>, |
| 2137 | class = _EnableIf<!__is_allocator<_Hash>::value>, |
| 2138 | class = _EnableIf<!is_integral<_Hash>::value>, |
| 2139 | class = _EnableIf<!__is_allocator<_Pred>::value>, |
| 2140 | class = _EnableIf<__is_allocator<_Allocator>::value>> |
| 2141 | unordered_multimap(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type = 0, |
| 2142 | _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator()) |
| 2143 | -> unordered_multimap<remove_const_t<_Key>, _Tp, _Hash, _Pred, _Allocator>; |
| 2144 | |
| 2145 | template<class _InputIterator, class _Allocator, |
| 2146 | class = _EnableIf<__is_allocator<_Allocator>::value>> |
| 2147 | unordered_multimap(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Allocator) |
| 2148 | -> unordered_multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, |
| 2149 | hash<__iter_key_type<_InputIterator>>, equal_to<__iter_key_type<_InputIterator>>, _Allocator>; |
| 2150 | |
| 2151 | template<class _InputIterator, class _Allocator, |
| 2152 | class = _EnableIf<__is_allocator<_Allocator>::value>> |
| 2153 | unordered_multimap(_InputIterator, _InputIterator, _Allocator) |
| 2154 | -> unordered_multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, |
| 2155 | hash<__iter_key_type<_InputIterator>>, equal_to<__iter_key_type<_InputIterator>>, _Allocator>; |
| 2156 | |
| 2157 | template<class _InputIterator, class _Hash, class _Allocator, |
| 2158 | class = _EnableIf<!__is_allocator<_Hash>::value>, |
| 2159 | class = _EnableIf<!is_integral<_Hash>::value>, |
| 2160 | class = _EnableIf<__is_allocator<_Allocator>::value>> |
| 2161 | unordered_multimap(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator) |
| 2162 | -> unordered_multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, |
| 2163 | _Hash, equal_to<__iter_key_type<_InputIterator>>, _Allocator>; |
| 2164 | |
| 2165 | template<class _Key, class _Tp, class _Allocator, |
| 2166 | class = _EnableIf<__is_allocator<_Allocator>::value>> |
| 2167 | unordered_multimap(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type, _Allocator) |
| 2168 | -> unordered_multimap<remove_const_t<_Key>, _Tp, |
| 2169 | hash<remove_const_t<_Key>>, |
| 2170 | equal_to<remove_const_t<_Key>>, _Allocator>; |
| 2171 | |
| 2172 | template<class _Key, class _Tp, class _Allocator, |
| 2173 | class = _EnableIf<__is_allocator<_Allocator>::value>> |
| 2174 | unordered_multimap(initializer_list<pair<_Key, _Tp>>, _Allocator) |
| 2175 | -> unordered_multimap<remove_const_t<_Key>, _Tp, |
| 2176 | hash<remove_const_t<_Key>>, |
| 2177 | equal_to<remove_const_t<_Key>>, _Allocator>; |
| 2178 | |
| 2179 | template<class _Key, class _Tp, class _Hash, class _Allocator, |
| 2180 | class = _EnableIf<!__is_allocator<_Hash>::value>, |
| 2181 | class = _EnableIf<!is_integral<_Hash>::value>, |
| 2182 | class = _EnableIf<__is_allocator<_Allocator>::value>> |
| 2183 | unordered_multimap(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator) |
| 2184 | -> unordered_multimap<remove_const_t<_Key>, _Tp, _Hash, |
| 2185 | equal_to<remove_const_t<_Key>>, _Allocator>; |
| 2186 | #endif |
| 2187 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2188 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 2189 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 2190 | size_type __n, const hasher& __hf, const key_equal& __eql) |
| 2191 | : __table_(__hf, __eql) |
| 2192 | { |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 | [diff] [blame] | 2193 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2194 | __get_db()->__insert_c(this); |
| 2195 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2196 | __table_.rehash(__n); |
| 2197 | } |
| 2198 | |
| 2199 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 2200 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 2201 | size_type __n, const hasher& __hf, const key_equal& __eql, |
| 2202 | const allocator_type& __a) |
Marshall Clow | 2a10c96 | 2016-08-17 05:58:40 | [diff] [blame] | 2203 | : __table_(__hf, __eql, typename __table::allocator_type(__a)) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2204 | { |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 | [diff] [blame] | 2205 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2206 | __get_db()->__insert_c(this); |
| 2207 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2208 | __table_.rehash(__n); |
| 2209 | } |
| 2210 | |
| 2211 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 2212 | template <class _InputIterator> |
| 2213 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 2214 | _InputIterator __first, _InputIterator __last) |
| 2215 | { |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 | [diff] [blame] | 2216 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2217 | __get_db()->__insert_c(this); |
| 2218 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2219 | insert(__first, __last); |
| 2220 | } |
| 2221 | |
| 2222 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 2223 | template <class _InputIterator> |
| 2224 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 2225 | _InputIterator __first, _InputIterator __last, size_type __n, |
| 2226 | const hasher& __hf, const key_equal& __eql) |
| 2227 | : __table_(__hf, __eql) |
| 2228 | { |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 | [diff] [blame] | 2229 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2230 | __get_db()->__insert_c(this); |
| 2231 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2232 | __table_.rehash(__n); |
| 2233 | insert(__first, __last); |
| 2234 | } |
| 2235 | |
| 2236 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 2237 | template <class _InputIterator> |
| 2238 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 2239 | _InputIterator __first, _InputIterator __last, size_type __n, |
| 2240 | const hasher& __hf, const key_equal& __eql, const allocator_type& __a) |
Marshall Clow | 2a10c96 | 2016-08-17 05:58:40 | [diff] [blame] | 2241 | : __table_(__hf, __eql, typename __table::allocator_type(__a)) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2242 | { |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 | [diff] [blame] | 2243 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2244 | __get_db()->__insert_c(this); |
| 2245 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2246 | __table_.rehash(__n); |
| 2247 | insert(__first, __last); |
| 2248 | } |
| 2249 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2250 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 | [diff] [blame] | 2251 | inline |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2252 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 2253 | const allocator_type& __a) |
Marshall Clow | 2a10c96 | 2016-08-17 05:58:40 | [diff] [blame] | 2254 | : __table_(typename __table::allocator_type(__a)) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2255 | { |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 | [diff] [blame] | 2256 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2257 | __get_db()->__insert_c(this); |
| 2258 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2259 | } |
| 2260 | |
| 2261 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 2262 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 2263 | const unordered_multimap& __u) |
| 2264 | : __table_(__u.__table_) |
| 2265 | { |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 | [diff] [blame] | 2266 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2267 | __get_db()->__insert_c(this); |
| 2268 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2269 | __table_.rehash(__u.bucket_count()); |
| 2270 | insert(__u.begin(), __u.end()); |
| 2271 | } |
| 2272 | |
| 2273 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 2274 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 2275 | const unordered_multimap& __u, const allocator_type& __a) |
Marshall Clow | 2a10c96 | 2016-08-17 05:58:40 | [diff] [blame] | 2276 | : __table_(__u.__table_, typename __table::allocator_type(__a)) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2277 | { |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 | [diff] [blame] | 2278 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2279 | __get_db()->__insert_c(this); |
| 2280 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2281 | __table_.rehash(__u.bucket_count()); |
| 2282 | insert(__u.begin(), __u.end()); |
| 2283 | } |
| 2284 | |
Eric Fiselier | 6a470bc | 2017-04-18 22:50:56 | [diff] [blame] | 2285 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2286 | |
| 2287 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 | [diff] [blame] | 2288 | inline |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2289 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 2290 | unordered_multimap&& __u) |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 2291 | _NOEXCEPT_(is_nothrow_move_constructible<__table>::value) |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 2292 | : __table_(_VSTD::move(__u.__table_)) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2293 | { |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 | [diff] [blame] | 2294 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2295 | __get_db()->__insert_c(this); |
Howard Hinnant | 4c80bfb | 2013-07-30 21:04:42 | [diff] [blame] | 2296 | __get_db()->swap(this, &__u); |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 | [diff] [blame] | 2297 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2298 | } |
| 2299 | |
| 2300 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 2301 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 2302 | unordered_multimap&& __u, const allocator_type& __a) |
Marshall Clow | 2a10c96 | 2016-08-17 05:58:40 | [diff] [blame] | 2303 | : __table_(_VSTD::move(__u.__table_), typename __table::allocator_type(__a)) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2304 | { |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 | [diff] [blame] | 2305 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2306 | __get_db()->__insert_c(this); |
| 2307 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2308 | if (__a != __u.get_allocator()) |
| 2309 | { |
| 2310 | iterator __i = __u.begin(); |
| 2311 | while (__u.size() != 0) |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 | [diff] [blame] | 2312 | { |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2313 | __table_.__insert_multi( |
Erik Pilkington | f52318b | 2018-06-04 20:38:23 | [diff] [blame] | 2314 | __u.__table_.remove((__i++).__i_)->__value_.__move()); |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 | [diff] [blame] | 2315 | } |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2316 | } |
Howard Hinnant | 4c80bfb | 2013-07-30 21:04:42 | [diff] [blame] | 2317 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2318 | else |
| 2319 | __get_db()->swap(this, &__u); |
| 2320 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2321 | } |
| 2322 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2323 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 2324 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 2325 | initializer_list<value_type> __il) |
| 2326 | { |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 | [diff] [blame] | 2327 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2328 | __get_db()->__insert_c(this); |
| 2329 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2330 | insert(__il.begin(), __il.end()); |
| 2331 | } |
| 2332 | |
| 2333 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 2334 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 2335 | initializer_list<value_type> __il, size_type __n, const hasher& __hf, |
| 2336 | const key_equal& __eql) |
| 2337 | : __table_(__hf, __eql) |
| 2338 | { |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 | [diff] [blame] | 2339 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2340 | __get_db()->__insert_c(this); |
| 2341 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2342 | __table_.rehash(__n); |
| 2343 | insert(__il.begin(), __il.end()); |
| 2344 | } |
| 2345 | |
| 2346 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 2347 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 2348 | initializer_list<value_type> __il, size_type __n, const hasher& __hf, |
| 2349 | const key_equal& __eql, const allocator_type& __a) |
Marshall Clow | 2a10c96 | 2016-08-17 05:58:40 | [diff] [blame] | 2350 | : __table_(__hf, __eql, typename __table::allocator_type(__a)) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2351 | { |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 | [diff] [blame] | 2352 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2353 | __get_db()->__insert_c(this); |
| 2354 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2355 | __table_.rehash(__n); |
| 2356 | insert(__il.begin(), __il.end()); |
| 2357 | } |
| 2358 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2359 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 | [diff] [blame] | 2360 | inline |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2361 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& |
| 2362 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_multimap&& __u) |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 2363 | _NOEXCEPT_(is_nothrow_move_assignable<__table>::value) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2364 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 2365 | __table_ = _VSTD::move(__u.__table_); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2366 | return *this; |
| 2367 | } |
| 2368 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2369 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 | [diff] [blame] | 2370 | inline |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2371 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& |
| 2372 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=( |
| 2373 | initializer_list<value_type> __il) |
| 2374 | { |
| 2375 | __table_.__assign_multi(__il.begin(), __il.end()); |
| 2376 | return *this; |
| 2377 | } |
| 2378 | |
Eric Fiselier | 6a470bc | 2017-04-18 22:50:56 | [diff] [blame] | 2379 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 | [diff] [blame] | 2380 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2381 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2382 | |
| 2383 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 2384 | template <class _InputIterator> |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 | [diff] [blame] | 2385 | inline |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2386 | void |
| 2387 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, |
| 2388 | _InputIterator __last) |
| 2389 | { |
| 2390 | for (; __first != __last; ++__first) |
| 2391 | __table_.__insert_multi(*__first); |
| 2392 | } |
| 2393 | |
| 2394 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 2395 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2396 | void |
| 2397 | swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, |
| 2398 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 | [diff] [blame] | 2399 | _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2400 | { |
| 2401 | __x.swap(__y); |
| 2402 | } |
| 2403 | |
Marshall Clow | f60c63c0 | 2018-12-14 18:49:35 | [diff] [blame] | 2404 | #if _LIBCPP_STD_VER > 17 |
| 2405 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc, class _Predicate> |
| 2406 | inline _LIBCPP_INLINE_VISIBILITY |
| 2407 | void erase_if(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __c, _Predicate __pred) |
| 2408 | { __libcpp_erase_if_container(__c, __pred); } |
| 2409 | #endif |
| 2410 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2411 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 2412 | bool |
| 2413 | operator==(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, |
| 2414 | const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) |
| 2415 | { |
| 2416 | if (__x.size() != __y.size()) |
| 2417 | return false; |
| 2418 | typedef typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator |
| 2419 | const_iterator; |
| 2420 | typedef pair<const_iterator, const_iterator> _EqRng; |
| 2421 | for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;) |
| 2422 | { |
| 2423 | _EqRng __xeq = __x.equal_range(__i->first); |
| 2424 | _EqRng __yeq = __y.equal_range(__i->first); |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 2425 | if (_VSTD::distance(__xeq.first, __xeq.second) != |
| 2426 | _VSTD::distance(__yeq.first, __yeq.second) || |
| 2427 | !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first)) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2428 | return false; |
| 2429 | __i = __xeq.second; |
| 2430 | } |
| 2431 | return true; |
| 2432 | } |
| 2433 | |
| 2434 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | 789847d | 2010-09-23 18:58:28 | [diff] [blame] | 2435 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 2436 | bool |
| 2437 | operator!=(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, |
| 2438 | const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) |
| 2439 | { |
| 2440 | return !(__x == __y); |
| 2441 | } |
| 2442 | |
| 2443 | _LIBCPP_END_NAMESPACE_STD |
| 2444 | |
| 2445 | #endif // _LIBCPP_UNORDERED_MAP |