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