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