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