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// standard-mandated includes 550 551// [iterator.range] 552#include <__iterator/access.h> 553#include <__iterator/data.h> 554#include <__iterator/empty.h> 555#include <__iterator/reverse_access.h> 556#include <__iterator/size.h> 557 558// [associative.map.syn] 559#include <compare> 560#include <initializer_list> 561 562#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 563# pragma GCC system_header 564#endif 565 566_LIBCPP_BEGIN_NAMESPACE_STD 567 568template <class _Key, class _CP, class _Compare, 569 bool = is_empty<_Compare>::value && !__libcpp_is_final<_Compare>::value> 570class __map_value_compare 571 : private _Compare 572{ 573public: 574 _LIBCPP_INLINE_VISIBILITY 575 __map_value_compare() 576 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value) 577 : _Compare() {} 578 _LIBCPP_INLINE_VISIBILITY 579 __map_value_compare(_Compare c) 580 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value) 581 : _Compare(c) {} 582 _LIBCPP_INLINE_VISIBILITY 583 const _Compare& key_comp() const _NOEXCEPT {return *this;} 584 _LIBCPP_INLINE_VISIBILITY 585 bool operator()(const _CP& __x, const _CP& __y) const 586 {return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y.__get_value().first);} 587 _LIBCPP_INLINE_VISIBILITY 588 bool operator()(const _CP& __x, const _Key& __y) const 589 {return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y);} 590 _LIBCPP_INLINE_VISIBILITY 591 bool operator()(const _Key& __x, const _CP& __y) const 592 {return static_cast<const _Compare&>(*this)(__x, __y.__get_value().first);} 593 void swap(__map_value_compare& __y) 594 _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value) 595 { 596 using _VSTD::swap; 597 swap(static_cast<_Compare&>(*this), static_cast<_Compare&>(__y)); 598 } 599 600#if _LIBCPP_STD_VER > 11 601 template <typename _K2> 602 _LIBCPP_INLINE_VISIBILITY 603 bool operator()(const _K2& __x, const _CP& __y) const 604 {return static_cast<const _Compare&>(*this)(__x, __y.__get_value().first);} 605 606 template <typename _K2> 607 _LIBCPP_INLINE_VISIBILITY 608 bool operator()(const _CP& __x, const _K2& __y) const 609 {return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y);} 610#endif 611}; 612 613template <class _Key, class _CP, class _Compare> 614class __map_value_compare<_Key, _CP, _Compare, false> 615{ 616 _Compare comp; 617 618public: 619 _LIBCPP_INLINE_VISIBILITY 620 __map_value_compare() 621 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value) 622 : comp() {} 623 _LIBCPP_INLINE_VISIBILITY 624 __map_value_compare(_Compare c) 625 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value) 626 : comp(c) {} 627 _LIBCPP_INLINE_VISIBILITY 628 const _Compare& key_comp() const _NOEXCEPT {return comp;} 629 630 _LIBCPP_INLINE_VISIBILITY 631 bool operator()(const _CP& __x, const _CP& __y) const 632 {return comp(__x.__get_value().first, __y.__get_value().first);} 633 _LIBCPP_INLINE_VISIBILITY 634 bool operator()(const _CP& __x, const _Key& __y) const 635 {return comp(__x.__get_value().first, __y);} 636 _LIBCPP_INLINE_VISIBILITY 637 bool operator()(const _Key& __x, const _CP& __y) const 638 {return comp(__x, __y.__get_value().first);} 639 void swap(__map_value_compare& __y) 640 _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value) 641 { 642 using _VSTD::swap; 643 swap(comp, __y.comp); 644 } 645 646#if _LIBCPP_STD_VER > 11 647 template <typename _K2> 648 _LIBCPP_INLINE_VISIBILITY 649 bool operator()(const _K2& __x, const _CP& __y) const 650 {return comp(__x, __y.__get_value().first);} 651 652 template <typename _K2> 653 _LIBCPP_INLINE_VISIBILITY 654 bool operator()(const _CP& __x, const _K2& __y) const 655 {return comp(__x.__get_value().first, __y);} 656#endif 657}; 658 659template <class _Key, class _CP, class _Compare, bool __b> 660inline _LIBCPP_INLINE_VISIBILITY 661void 662swap(__map_value_compare<_Key, _CP, _Compare, __b>& __x, 663 __map_value_compare<_Key, _CP, _Compare, __b>& __y) 664 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) 665{ 666 __x.swap(__y); 667} 668 669template <class _Allocator> 670class __map_node_destructor 671{ 672 typedef _Allocator allocator_type; 673 typedef allocator_traits<allocator_type> __alloc_traits; 674 675public: 676 typedef typename __alloc_traits::pointer pointer; 677 678private: 679 allocator_type& __na_; 680 681 __map_node_destructor& operator=(const __map_node_destructor&); 682 683public: 684 bool __first_constructed; 685 bool __second_constructed; 686 687 _LIBCPP_INLINE_VISIBILITY 688 explicit __map_node_destructor(allocator_type& __na) _NOEXCEPT 689 : __na_(__na), 690 __first_constructed(false), 691 __second_constructed(false) 692 {} 693 694#ifndef _LIBCPP_CXX03_LANG 695 _LIBCPP_INLINE_VISIBILITY 696 __map_node_destructor(__tree_node_destructor<allocator_type>&& __x) _NOEXCEPT 697 : __na_(__x.__na_), 698 __first_constructed(__x.__value_constructed), 699 __second_constructed(__x.__value_constructed) 700 { 701 __x.__value_constructed = false; 702 } 703#endif // _LIBCPP_CXX03_LANG 704 705 _LIBCPP_INLINE_VISIBILITY 706 void operator()(pointer __p) _NOEXCEPT 707 { 708 if (__second_constructed) 709 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__get_value().second)); 710 if (__first_constructed) 711 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__get_value().first)); 712 if (__p) 713 __alloc_traits::deallocate(__na_, __p, 1); 714 } 715}; 716 717template <class _Key, class _Tp, class _Compare, class _Allocator> 718 class map; 719template <class _Key, class _Tp, class _Compare, class _Allocator> 720 class multimap; 721template <class _TreeIterator> class __map_const_iterator; 722 723#ifndef _LIBCPP_CXX03_LANG 724 725template <class _Key, class _Tp> 726struct _LIBCPP_STANDALONE_DEBUG __value_type 727{ 728 typedef _Key key_type; 729 typedef _Tp mapped_type; 730 typedef pair<const key_type, mapped_type> value_type; 731 typedef pair<key_type&, mapped_type&> __nc_ref_pair_type; 732 typedef pair<key_type&&, mapped_type&&> __nc_rref_pair_type; 733 734private: 735 value_type __cc; 736 737public: 738 _LIBCPP_INLINE_VISIBILITY 739 value_type& __get_value() 740 { 741#if _LIBCPP_STD_VER > 14 742 return *_VSTD::launder(_VSTD::addressof(__cc)); 743#else 744 return __cc; 745#endif 746 } 747 748 _LIBCPP_INLINE_VISIBILITY 749 const value_type& __get_value() const 750 { 751#if _LIBCPP_STD_VER > 14 752 return *_VSTD::launder(_VSTD::addressof(__cc)); 753#else 754 return __cc; 755#endif 756 } 757 758 _LIBCPP_INLINE_VISIBILITY 759 __nc_ref_pair_type __ref() 760 { 761 value_type& __v = __get_value(); 762 return __nc_ref_pair_type(const_cast<key_type&>(__v.first), __v.second); 763 } 764 765 _LIBCPP_INLINE_VISIBILITY 766 __nc_rref_pair_type __move() 767 { 768 value_type& __v = __get_value(); 769 return __nc_rref_pair_type( 770 _VSTD::move(const_cast<key_type&>(__v.first)), 771 _VSTD::move(__v.second)); 772 } 773 774 _LIBCPP_INLINE_VISIBILITY 775 __value_type& operator=(const __value_type& __v) 776 { 777 __ref() = __v.__get_value(); 778 return *this; 779 } 780 781 _LIBCPP_INLINE_VISIBILITY 782 __value_type& operator=(__value_type&& __v) 783 { 784 __ref() = __v.__move(); 785 return *this; 786 } 787 788 template <class _ValueTp, 789 class = typename enable_if< 790 __is_same_uncvref<_ValueTp, value_type>::value 791 >::type 792 > 793 _LIBCPP_INLINE_VISIBILITY 794 __value_type& operator=(_ValueTp&& __v) 795 { 796 __ref() = _VSTD::forward<_ValueTp>(__v); 797 return *this; 798 } 799 800private: 801 __value_type() = delete; 802 ~__value_type() = delete; 803 __value_type(const __value_type&) = delete; 804 __value_type(__value_type&&) = delete; 805}; 806 807#else 808 809template <class _Key, class _Tp> 810struct __value_type 811{ 812 typedef _Key key_type; 813 typedef _Tp mapped_type; 814 typedef pair<const key_type, mapped_type> value_type; 815 816private: 817 value_type __cc; 818 819public: 820 _LIBCPP_INLINE_VISIBILITY 821 value_type& __get_value() { return __cc; } 822 _LIBCPP_INLINE_VISIBILITY 823 const value_type& __get_value() const { return __cc; } 824 825private: 826 __value_type(); 827 __value_type(__value_type const&); 828 __value_type& operator=(__value_type const&); 829 ~__value_type(); 830}; 831 832#endif // _LIBCPP_CXX03_LANG 833 834template <class _Tp> 835struct __extract_key_value_types; 836 837template <class _Key, class _Tp> 838struct __extract_key_value_types<__value_type<_Key, _Tp> > 839{ 840 typedef _Key const __key_type; 841 typedef _Tp __mapped_type; 842}; 843 844template <class _TreeIterator> 845class _LIBCPP_TEMPLATE_VIS __map_iterator 846{ 847 typedef typename _TreeIterator::_NodeTypes _NodeTypes; 848 typedef typename _TreeIterator::__pointer_traits __pointer_traits; 849 850 _TreeIterator __i_; 851 852public: 853 typedef bidirectional_iterator_tag iterator_category; 854 typedef typename _NodeTypes::__map_value_type value_type; 855 typedef typename _TreeIterator::difference_type difference_type; 856 typedef value_type& reference; 857 typedef typename _NodeTypes::__map_value_type_pointer pointer; 858 859 _LIBCPP_INLINE_VISIBILITY 860 __map_iterator() _NOEXCEPT {} 861 862 _LIBCPP_INLINE_VISIBILITY 863 __map_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {} 864 865 _LIBCPP_INLINE_VISIBILITY 866 reference operator*() const {return __i_->__get_value();} 867 _LIBCPP_INLINE_VISIBILITY 868 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());} 869 870 _LIBCPP_INLINE_VISIBILITY 871 __map_iterator& operator++() {++__i_; return *this;} 872 _LIBCPP_INLINE_VISIBILITY 873 __map_iterator operator++(int) 874 { 875 __map_iterator __t(*this); 876 ++(*this); 877 return __t; 878 } 879 880 _LIBCPP_INLINE_VISIBILITY 881 __map_iterator& operator--() {--__i_; return *this;} 882 _LIBCPP_INLINE_VISIBILITY 883 __map_iterator operator--(int) 884 { 885 __map_iterator __t(*this); 886 --(*this); 887 return __t; 888 } 889 890 friend _LIBCPP_INLINE_VISIBILITY 891 bool operator==(const __map_iterator& __x, const __map_iterator& __y) 892 {return __x.__i_ == __y.__i_;} 893 friend 894 _LIBCPP_INLINE_VISIBILITY 895 bool operator!=(const __map_iterator& __x, const __map_iterator& __y) 896 {return __x.__i_ != __y.__i_;} 897 898 template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS map; 899 template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS multimap; 900 template <class> friend class _LIBCPP_TEMPLATE_VIS __map_const_iterator; 901}; 902 903template <class _TreeIterator> 904class _LIBCPP_TEMPLATE_VIS __map_const_iterator 905{ 906 typedef typename _TreeIterator::_NodeTypes _NodeTypes; 907 typedef typename _TreeIterator::__pointer_traits __pointer_traits; 908 909 _TreeIterator __i_; 910 911public: 912 typedef bidirectional_iterator_tag iterator_category; 913 typedef typename _NodeTypes::__map_value_type value_type; 914 typedef typename _TreeIterator::difference_type difference_type; 915 typedef const value_type& reference; 916 typedef typename _NodeTypes::__const_map_value_type_pointer pointer; 917 918 _LIBCPP_INLINE_VISIBILITY 919 __map_const_iterator() _NOEXCEPT {} 920 921 _LIBCPP_INLINE_VISIBILITY 922 __map_const_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {} 923 _LIBCPP_INLINE_VISIBILITY 924 __map_const_iterator(__map_iterator< 925 typename _TreeIterator::__non_const_iterator> __i) _NOEXCEPT 926 : __i_(__i.__i_) {} 927 928 _LIBCPP_INLINE_VISIBILITY 929 reference operator*() const {return __i_->__get_value();} 930 _LIBCPP_INLINE_VISIBILITY 931 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());} 932 933 _LIBCPP_INLINE_VISIBILITY 934 __map_const_iterator& operator++() {++__i_; return *this;} 935 _LIBCPP_INLINE_VISIBILITY 936 __map_const_iterator operator++(int) 937 { 938 __map_const_iterator __t(*this); 939 ++(*this); 940 return __t; 941 } 942 943 _LIBCPP_INLINE_VISIBILITY 944 __map_const_iterator& operator--() {--__i_; return *this;} 945 _LIBCPP_INLINE_VISIBILITY 946 __map_const_iterator operator--(int) 947 { 948 __map_const_iterator __t(*this); 949 --(*this); 950 return __t; 951 } 952 953 friend _LIBCPP_INLINE_VISIBILITY 954 bool operator==(const __map_const_iterator& __x, const __map_const_iterator& __y) 955 {return __x.__i_ == __y.__i_;} 956 friend _LIBCPP_INLINE_VISIBILITY 957 bool operator!=(const __map_const_iterator& __x, const __map_const_iterator& __y) 958 {return __x.__i_ != __y.__i_;} 959 960 template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS map; 961 template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS multimap; 962 template <class, class, class> friend class _LIBCPP_TEMPLATE_VIS __tree_const_iterator; 963}; 964 965template <class _Key, class _Tp, class _Compare = less<_Key>, 966 class _Allocator = allocator<pair<const _Key, _Tp> > > 967class _LIBCPP_TEMPLATE_VIS map 968{ 969public: 970 // types: 971 typedef _Key key_type; 972 typedef _Tp mapped_type; 973 typedef pair<const key_type, mapped_type> value_type; 974 typedef __type_identity_t<_Compare> key_compare; 975 typedef __type_identity_t<_Allocator> allocator_type; 976 typedef value_type& reference; 977 typedef const value_type& const_reference; 978 979 static_assert((is_same<typename allocator_type::value_type, value_type>::value), 980 "Allocator::value_type must be same type as value_type"); 981 982 class _LIBCPP_TEMPLATE_VIS value_compare 983 : public __binary_function<value_type, value_type, bool> 984 { 985 friend class map; 986 protected: 987 key_compare comp; 988 989 _LIBCPP_INLINE_VISIBILITY value_compare(key_compare c) : comp(c) {} 990 public: 991 _LIBCPP_INLINE_VISIBILITY 992 bool operator()(const value_type& __x, const value_type& __y) const 993 {return comp(__x.first, __y.first);} 994 }; 995 996private: 997 998 typedef _VSTD::__value_type<key_type, mapped_type> __value_type; 999 typedef __map_value_compare<key_type, __value_type, key_compare> __vc; 1000 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>, 1001 __value_type>::type __allocator_type; 1002 typedef __tree<__value_type, __vc, __allocator_type> __base; 1003 typedef typename __base::__node_traits __node_traits; 1004 typedef allocator_traits<allocator_type> __alloc_traits; 1005 1006 __base __tree_; 1007 1008public: 1009 typedef typename __alloc_traits::pointer pointer; 1010 typedef typename __alloc_traits::const_pointer const_pointer; 1011 typedef typename __alloc_traits::size_type size_type; 1012 typedef typename __alloc_traits::difference_type difference_type; 1013 typedef __map_iterator<typename __base::iterator> iterator; 1014 typedef __map_const_iterator<typename __base::const_iterator> const_iterator; 1015 typedef _VSTD::reverse_iterator<iterator> reverse_iterator; 1016 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; 1017 1018#if _LIBCPP_STD_VER > 14 1019 typedef __map_node_handle<typename __base::__node, allocator_type> node_type; 1020 typedef __insert_return_type<iterator, node_type> insert_return_type; 1021#endif 1022 1023 template <class _Key2, class _Value2, class _Comp2, class _Alloc2> 1024 friend class _LIBCPP_TEMPLATE_VIS map; 1025 template <class _Key2, class _Value2, class _Comp2, class _Alloc2> 1026 friend class _LIBCPP_TEMPLATE_VIS multimap; 1027 1028 _LIBCPP_INLINE_VISIBILITY 1029 map() 1030 _NOEXCEPT_( 1031 is_nothrow_default_constructible<allocator_type>::value && 1032 is_nothrow_default_constructible<key_compare>::value && 1033 is_nothrow_copy_constructible<key_compare>::value) 1034 : __tree_(__vc(key_compare())) {} 1035 1036 _LIBCPP_INLINE_VISIBILITY 1037 explicit map(const key_compare& __comp) 1038 _NOEXCEPT_( 1039 is_nothrow_default_constructible<allocator_type>::value && 1040 is_nothrow_copy_constructible<key_compare>::value) 1041 : __tree_(__vc(__comp)) {} 1042 1043 _LIBCPP_INLINE_VISIBILITY 1044 explicit map(const key_compare& __comp, const allocator_type& __a) 1045 : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {} 1046 1047 template <class _InputIterator> 1048 _LIBCPP_INLINE_VISIBILITY 1049 map(_InputIterator __f, _InputIterator __l, 1050 const key_compare& __comp = key_compare()) 1051 : __tree_(__vc(__comp)) 1052 { 1053 insert(__f, __l); 1054 } 1055 1056 template <class _InputIterator> 1057 _LIBCPP_INLINE_VISIBILITY 1058 map(_InputIterator __f, _InputIterator __l, 1059 const key_compare& __comp, const allocator_type& __a) 1060 : __tree_(__vc(__comp), typename __base::allocator_type(__a)) 1061 { 1062 insert(__f, __l); 1063 } 1064 1065#if _LIBCPP_STD_VER > 11 1066 template <class _InputIterator> 1067 _LIBCPP_INLINE_VISIBILITY 1068 map(_InputIterator __f, _InputIterator __l, const allocator_type& __a) 1069 : map(__f, __l, key_compare(), __a) {} 1070#endif 1071 1072 _LIBCPP_INLINE_VISIBILITY 1073 map(const map& __m) 1074 : __tree_(__m.__tree_) 1075 { 1076 insert(__m.begin(), __m.end()); 1077 } 1078 1079 _LIBCPP_INLINE_VISIBILITY 1080 map& operator=(const map& __m) 1081 { 1082#ifndef _LIBCPP_CXX03_LANG 1083 __tree_ = __m.__tree_; 1084#else 1085 if (this != _VSTD::addressof(__m)) { 1086 __tree_.clear(); 1087 __tree_.value_comp() = __m.__tree_.value_comp(); 1088 __tree_.__copy_assign_alloc(__m.__tree_); 1089 insert(__m.begin(), __m.end()); 1090 } 1091#endif 1092 return *this; 1093 } 1094 1095#ifndef _LIBCPP_CXX03_LANG 1096 1097 _LIBCPP_INLINE_VISIBILITY 1098 map(map&& __m) 1099 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value) 1100 : __tree_(_VSTD::move(__m.__tree_)) 1101 { 1102 } 1103 1104 map(map&& __m, const allocator_type& __a); 1105 1106 _LIBCPP_INLINE_VISIBILITY 1107 map& operator=(map&& __m) 1108 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value) 1109 { 1110 __tree_ = _VSTD::move(__m.__tree_); 1111 return *this; 1112 } 1113 1114 _LIBCPP_INLINE_VISIBILITY 1115 map(initializer_list<value_type> __il, const key_compare& __comp = key_compare()) 1116 : __tree_(__vc(__comp)) 1117 { 1118 insert(__il.begin(), __il.end()); 1119 } 1120 1121 _LIBCPP_INLINE_VISIBILITY 1122 map(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a) 1123 : __tree_(__vc(__comp), typename __base::allocator_type(__a)) 1124 { 1125 insert(__il.begin(), __il.end()); 1126 } 1127 1128#if _LIBCPP_STD_VER > 11 1129 _LIBCPP_INLINE_VISIBILITY 1130 map(initializer_list<value_type> __il, const allocator_type& __a) 1131 : map(__il, key_compare(), __a) {} 1132#endif 1133 1134 _LIBCPP_INLINE_VISIBILITY 1135 map& operator=(initializer_list<value_type> __il) 1136 { 1137 __tree_.__assign_unique(__il.begin(), __il.end()); 1138 return *this; 1139 } 1140 1141#endif // _LIBCPP_CXX03_LANG 1142 1143 _LIBCPP_INLINE_VISIBILITY 1144 explicit map(const allocator_type& __a) 1145 : __tree_(typename __base::allocator_type(__a)) 1146 { 1147 } 1148 1149 _LIBCPP_INLINE_VISIBILITY 1150 map(const map& __m, const allocator_type& __a) 1151 : __tree_(__m.__tree_.value_comp(), typename __base::allocator_type(__a)) 1152 { 1153 insert(__m.begin(), __m.end()); 1154 } 1155 1156 _LIBCPP_INLINE_VISIBILITY 1157 ~map() { 1158 static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), ""); 1159 } 1160 1161 _LIBCPP_INLINE_VISIBILITY 1162 iterator begin() _NOEXCEPT {return __tree_.begin();} 1163 _LIBCPP_INLINE_VISIBILITY 1164 const_iterator begin() const _NOEXCEPT {return __tree_.begin();} 1165 _LIBCPP_INLINE_VISIBILITY 1166 iterator end() _NOEXCEPT {return __tree_.end();} 1167 _LIBCPP_INLINE_VISIBILITY 1168 const_iterator end() const _NOEXCEPT {return __tree_.end();} 1169 1170 _LIBCPP_INLINE_VISIBILITY 1171 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());} 1172 _LIBCPP_INLINE_VISIBILITY 1173 const_reverse_iterator rbegin() const _NOEXCEPT 1174 {return const_reverse_iterator(end());} 1175 _LIBCPP_INLINE_VISIBILITY 1176 reverse_iterator rend() _NOEXCEPT 1177 {return reverse_iterator(begin());} 1178 _LIBCPP_INLINE_VISIBILITY 1179 const_reverse_iterator rend() const _NOEXCEPT 1180 {return const_reverse_iterator(begin());} 1181 1182 _LIBCPP_INLINE_VISIBILITY 1183 const_iterator cbegin() const _NOEXCEPT {return begin();} 1184 _LIBCPP_INLINE_VISIBILITY 1185 const_iterator cend() const _NOEXCEPT {return end();} 1186 _LIBCPP_INLINE_VISIBILITY 1187 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();} 1188 _LIBCPP_INLINE_VISIBILITY 1189 const_reverse_iterator crend() const _NOEXCEPT {return rend();} 1190 1191 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 1192 bool empty() const _NOEXCEPT {return __tree_.size() == 0;} 1193 _LIBCPP_INLINE_VISIBILITY 1194 size_type size() const _NOEXCEPT {return __tree_.size();} 1195 _LIBCPP_INLINE_VISIBILITY 1196 size_type max_size() const _NOEXCEPT {return __tree_.max_size();} 1197 1198 mapped_type& operator[](const key_type& __k); 1199#ifndef _LIBCPP_CXX03_LANG 1200 mapped_type& operator[](key_type&& __k); 1201#endif 1202 1203 mapped_type& at(const key_type& __k); 1204 const mapped_type& at(const key_type& __k) const; 1205 1206 _LIBCPP_INLINE_VISIBILITY 1207 allocator_type get_allocator() const _NOEXCEPT {return allocator_type(__tree_.__alloc());} 1208 _LIBCPP_INLINE_VISIBILITY 1209 key_compare key_comp() const {return __tree_.value_comp().key_comp();} 1210 _LIBCPP_INLINE_VISIBILITY 1211 value_compare value_comp() const {return value_compare(__tree_.value_comp().key_comp());} 1212 1213#ifndef _LIBCPP_CXX03_LANG 1214 template <class ..._Args> 1215 _LIBCPP_INLINE_VISIBILITY 1216 pair<iterator, bool> emplace(_Args&& ...__args) { 1217 return __tree_.__emplace_unique(_VSTD::forward<_Args>(__args)...); 1218 } 1219 1220 template <class ..._Args> 1221 _LIBCPP_INLINE_VISIBILITY 1222 iterator emplace_hint(const_iterator __p, _Args&& ...__args) { 1223 return __tree_.__emplace_hint_unique(__p.__i_, _VSTD::forward<_Args>(__args)...); 1224 } 1225 1226 template <class _Pp, 1227 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type> 1228 _LIBCPP_INLINE_VISIBILITY 1229 pair<iterator, bool> insert(_Pp&& __p) 1230 {return __tree_.__insert_unique(_VSTD::forward<_Pp>(__p));} 1231 1232 template <class _Pp, 1233 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type> 1234 _LIBCPP_INLINE_VISIBILITY 1235 iterator insert(const_iterator __pos, _Pp&& __p) 1236 {return __tree_.__insert_unique(__pos.__i_, _VSTD::forward<_Pp>(__p));} 1237 1238#endif // _LIBCPP_CXX03_LANG 1239 1240 _LIBCPP_INLINE_VISIBILITY 1241 pair<iterator, bool> 1242 insert(const value_type& __v) {return __tree_.__insert_unique(__v);} 1243 1244 _LIBCPP_INLINE_VISIBILITY 1245 iterator 1246 insert(const_iterator __p, const value_type& __v) 1247 {return __tree_.__insert_unique(__p.__i_, __v);} 1248 1249#ifndef _LIBCPP_CXX03_LANG 1250 _LIBCPP_INLINE_VISIBILITY 1251 pair<iterator, bool> 1252 insert(value_type&& __v) {return __tree_.__insert_unique(_VSTD::move(__v));} 1253 1254 _LIBCPP_INLINE_VISIBILITY 1255 iterator insert(const_iterator __p, value_type&& __v) 1256 {return __tree_.__insert_unique(__p.__i_, _VSTD::move(__v));} 1257 1258 _LIBCPP_INLINE_VISIBILITY 1259 void insert(initializer_list<value_type> __il) 1260 {insert(__il.begin(), __il.end());} 1261#endif 1262 1263 template <class _InputIterator> 1264 _LIBCPP_INLINE_VISIBILITY 1265 void insert(_InputIterator __f, _InputIterator __l) 1266 { 1267 for (const_iterator __e = cend(); __f != __l; ++__f) 1268 insert(__e.__i_, *__f); 1269 } 1270 1271#if _LIBCPP_STD_VER > 14 1272 1273 template <class... _Args> 1274 _LIBCPP_INLINE_VISIBILITY 1275 pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args) 1276 { 1277 return __tree_.__emplace_unique_key_args(__k, 1278 _VSTD::piecewise_construct, 1279 _VSTD::forward_as_tuple(__k), 1280 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)); 1281 } 1282 1283 template <class... _Args> 1284 _LIBCPP_INLINE_VISIBILITY 1285 pair<iterator, bool> try_emplace(key_type&& __k, _Args&&... __args) 1286 { 1287 return __tree_.__emplace_unique_key_args(__k, 1288 _VSTD::piecewise_construct, 1289 _VSTD::forward_as_tuple(_VSTD::move(__k)), 1290 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)); 1291 } 1292 1293 template <class... _Args> 1294 _LIBCPP_INLINE_VISIBILITY 1295 iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args) 1296 { 1297 return __tree_.__emplace_hint_unique_key_args(__h.__i_, __k, 1298 _VSTD::piecewise_construct, 1299 _VSTD::forward_as_tuple(__k), 1300 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)).first; 1301 } 1302 1303 template <class... _Args> 1304 _LIBCPP_INLINE_VISIBILITY 1305 iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args) 1306 { 1307 return __tree_.__emplace_hint_unique_key_args(__h.__i_, __k, 1308 _VSTD::piecewise_construct, 1309 _VSTD::forward_as_tuple(_VSTD::move(__k)), 1310 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)).first; 1311 } 1312 1313 template <class _Vp> 1314 _LIBCPP_INLINE_VISIBILITY 1315 pair<iterator, bool> insert_or_assign(const key_type& __k, _Vp&& __v) 1316 { 1317 iterator __p = lower_bound(__k); 1318 if ( __p != end() && !key_comp()(__k, __p->first)) 1319 { 1320 __p->second = _VSTD::forward<_Vp>(__v); 1321 return _VSTD::make_pair(__p, false); 1322 } 1323 return _VSTD::make_pair(emplace_hint(__p, __k, _VSTD::forward<_Vp>(__v)), true); 1324 } 1325 1326 template <class _Vp> 1327 _LIBCPP_INLINE_VISIBILITY 1328 pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v) 1329 { 1330 iterator __p = lower_bound(__k); 1331 if ( __p != end() && !key_comp()(__k, __p->first)) 1332 { 1333 __p->second = _VSTD::forward<_Vp>(__v); 1334 return _VSTD::make_pair(__p, false); 1335 } 1336 return _VSTD::make_pair(emplace_hint(__p, _VSTD::move(__k), _VSTD::forward<_Vp>(__v)), true); 1337 } 1338 1339 template <class _Vp> 1340 _LIBCPP_INLINE_VISIBILITY iterator insert_or_assign(const_iterator __h, 1341 const key_type& __k, 1342 _Vp&& __v) { 1343 auto [__r, __inserted] = __tree_.__emplace_hint_unique_key_args( 1344 __h.__i_, __k, __k, _VSTD::forward<_Vp>(__v)); 1345 1346 if (!__inserted) 1347 __r->__get_value().second = _VSTD::forward<_Vp>(__v); 1348 1349 return __r; 1350 } 1351 1352 template <class _Vp> 1353 _LIBCPP_INLINE_VISIBILITY iterator insert_or_assign(const_iterator __h, 1354 key_type&& __k, 1355 _Vp&& __v) { 1356 auto [__r, __inserted] = __tree_.__emplace_hint_unique_key_args( 1357 __h.__i_, __k, _VSTD::move(__k), _VSTD::forward<_Vp>(__v)); 1358 1359 if (!__inserted) 1360 __r->__get_value().second = _VSTD::forward<_Vp>(__v); 1361 1362 return __r; 1363 } 1364 1365#endif // _LIBCPP_STD_VER > 14 1366 1367 _LIBCPP_INLINE_VISIBILITY 1368 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);} 1369 _LIBCPP_INLINE_VISIBILITY 1370 iterator erase(iterator __p) {return __tree_.erase(__p.__i_);} 1371 _LIBCPP_INLINE_VISIBILITY 1372 size_type erase(const key_type& __k) 1373 {return __tree_.__erase_unique(__k);} 1374 _LIBCPP_INLINE_VISIBILITY 1375 iterator erase(const_iterator __f, const_iterator __l) 1376 {return __tree_.erase(__f.__i_, __l.__i_);} 1377 _LIBCPP_INLINE_VISIBILITY 1378 void clear() _NOEXCEPT {__tree_.clear();} 1379 1380#if _LIBCPP_STD_VER > 14 1381 _LIBCPP_INLINE_VISIBILITY 1382 insert_return_type insert(node_type&& __nh) 1383 { 1384 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(), 1385 "node_type with incompatible allocator passed to map::insert()"); 1386 return __tree_.template __node_handle_insert_unique< 1387 node_type, insert_return_type>(_VSTD::move(__nh)); 1388 } 1389 _LIBCPP_INLINE_VISIBILITY 1390 iterator insert(const_iterator __hint, node_type&& __nh) 1391 { 1392 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(), 1393 "node_type with incompatible allocator passed to map::insert()"); 1394 return __tree_.template __node_handle_insert_unique<node_type>( 1395 __hint.__i_, _VSTD::move(__nh)); 1396 } 1397 _LIBCPP_INLINE_VISIBILITY 1398 node_type extract(key_type const& __key) 1399 { 1400 return __tree_.template __node_handle_extract<node_type>(__key); 1401 } 1402 _LIBCPP_INLINE_VISIBILITY 1403 node_type extract(const_iterator __it) 1404 { 1405 return __tree_.template __node_handle_extract<node_type>(__it.__i_); 1406 } 1407 template <class _Compare2> 1408 _LIBCPP_INLINE_VISIBILITY 1409 void merge(map<key_type, mapped_type, _Compare2, allocator_type>& __source) 1410 { 1411 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), 1412 "merging container with incompatible allocator"); 1413 __tree_.__node_handle_merge_unique(__source.__tree_); 1414 } 1415 template <class _Compare2> 1416 _LIBCPP_INLINE_VISIBILITY 1417 void merge(map<key_type, mapped_type, _Compare2, allocator_type>&& __source) 1418 { 1419 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), 1420 "merging container with incompatible allocator"); 1421 __tree_.__node_handle_merge_unique(__source.__tree_); 1422 } 1423 template <class _Compare2> 1424 _LIBCPP_INLINE_VISIBILITY 1425 void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>& __source) 1426 { 1427 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), 1428 "merging container with incompatible allocator"); 1429 __tree_.__node_handle_merge_unique(__source.__tree_); 1430 } 1431 template <class _Compare2> 1432 _LIBCPP_INLINE_VISIBILITY 1433 void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>&& __source) 1434 { 1435 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), 1436 "merging container with incompatible allocator"); 1437 __tree_.__node_handle_merge_unique(__source.__tree_); 1438 } 1439#endif 1440 1441 _LIBCPP_INLINE_VISIBILITY 1442 void swap(map& __m) 1443 _NOEXCEPT_(__is_nothrow_swappable<__base>::value) 1444 {__tree_.swap(__m.__tree_);} 1445 1446 _LIBCPP_INLINE_VISIBILITY 1447 iterator find(const key_type& __k) {return __tree_.find(__k);} 1448 _LIBCPP_INLINE_VISIBILITY 1449 const_iterator find(const key_type& __k) const {return __tree_.find(__k);} 1450#if _LIBCPP_STD_VER > 11 1451 template <typename _K2> 1452 _LIBCPP_INLINE_VISIBILITY 1453 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type 1454 find(const _K2& __k) {return __tree_.find(__k);} 1455 template <typename _K2> 1456 _LIBCPP_INLINE_VISIBILITY 1457 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type 1458 find(const _K2& __k) const {return __tree_.find(__k);} 1459#endif 1460 1461 _LIBCPP_INLINE_VISIBILITY 1462 size_type count(const key_type& __k) const 1463 {return __tree_.__count_unique(__k);} 1464#if _LIBCPP_STD_VER > 11 1465 template <typename _K2> 1466 _LIBCPP_INLINE_VISIBILITY 1467 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type 1468 count(const _K2& __k) const {return __tree_.__count_multi(__k);} 1469#endif 1470 1471#if _LIBCPP_STD_VER > 17 1472 _LIBCPP_INLINE_VISIBILITY 1473 bool contains(const key_type& __k) const {return find(__k) != end();} 1474 template <typename _K2> 1475 _LIBCPP_INLINE_VISIBILITY 1476 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type 1477 contains(const _K2& __k) const { return find(__k) != end(); } 1478#endif // _LIBCPP_STD_VER > 17 1479 1480 _LIBCPP_INLINE_VISIBILITY 1481 iterator lower_bound(const key_type& __k) 1482 {return __tree_.lower_bound(__k);} 1483 _LIBCPP_INLINE_VISIBILITY 1484 const_iterator lower_bound(const key_type& __k) const 1485 {return __tree_.lower_bound(__k);} 1486#if _LIBCPP_STD_VER > 11 1487 template <typename _K2> 1488 _LIBCPP_INLINE_VISIBILITY 1489 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type 1490 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);} 1491 1492 template <typename _K2> 1493 _LIBCPP_INLINE_VISIBILITY 1494 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type 1495 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);} 1496#endif 1497 1498 _LIBCPP_INLINE_VISIBILITY 1499 iterator upper_bound(const key_type& __k) 1500 {return __tree_.upper_bound(__k);} 1501 _LIBCPP_INLINE_VISIBILITY 1502 const_iterator upper_bound(const key_type& __k) const 1503 {return __tree_.upper_bound(__k);} 1504#if _LIBCPP_STD_VER > 11 1505 template <typename _K2> 1506 _LIBCPP_INLINE_VISIBILITY 1507 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type 1508 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);} 1509 template <typename _K2> 1510 _LIBCPP_INLINE_VISIBILITY 1511 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type 1512 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);} 1513#endif 1514 1515 _LIBCPP_INLINE_VISIBILITY 1516 pair<iterator,iterator> equal_range(const key_type& __k) 1517 {return __tree_.__equal_range_unique(__k);} 1518 _LIBCPP_INLINE_VISIBILITY 1519 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const 1520 {return __tree_.__equal_range_unique(__k);} 1521#if _LIBCPP_STD_VER > 11 1522 template <typename _K2> 1523 _LIBCPP_INLINE_VISIBILITY 1524 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type 1525 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);} 1526 template <typename _K2> 1527 _LIBCPP_INLINE_VISIBILITY 1528 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type 1529 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);} 1530#endif 1531 1532private: 1533 typedef typename __base::__node __node; 1534 typedef typename __base::__node_allocator __node_allocator; 1535 typedef typename __base::__node_pointer __node_pointer; 1536 typedef typename __base::__node_base_pointer __node_base_pointer; 1537 typedef typename __base::__parent_pointer __parent_pointer; 1538 1539 typedef __map_node_destructor<__node_allocator> _Dp; 1540 typedef unique_ptr<__node, _Dp> __node_holder; 1541 1542#ifdef _LIBCPP_CXX03_LANG 1543 __node_holder __construct_node_with_key(const key_type& __k); 1544#endif 1545}; 1546 1547#if _LIBCPP_STD_VER >= 17 1548template<class _InputIterator, class _Compare = less<__iter_key_type<_InputIterator>>, 1549 class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>, 1550 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value, void>, 1551 class = enable_if_t<!__is_allocator<_Compare>::value, void>, 1552 class = enable_if_t<__is_allocator<_Allocator>::value, void>> 1553map(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator()) 1554 -> map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Compare, _Allocator>; 1555 1556template<class _Key, class _Tp, class _Compare = less<remove_const_t<_Key>>, 1557 class _Allocator = allocator<pair<const _Key, _Tp>>, 1558 class = enable_if_t<!__is_allocator<_Compare>::value, void>, 1559 class = enable_if_t<__is_allocator<_Allocator>::value, void>> 1560map(initializer_list<pair<_Key, _Tp>>, _Compare = _Compare(), _Allocator = _Allocator()) 1561 -> map<remove_const_t<_Key>, _Tp, _Compare, _Allocator>; 1562 1563template<class _InputIterator, class _Allocator, 1564 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value, void>, 1565 class = enable_if_t<__is_allocator<_Allocator>::value, void>> 1566map(_InputIterator, _InputIterator, _Allocator) 1567 -> map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, 1568 less<__iter_key_type<_InputIterator>>, _Allocator>; 1569 1570template<class _Key, class _Tp, class _Allocator, 1571 class = enable_if_t<__is_allocator<_Allocator>::value, void>> 1572map(initializer_list<pair<_Key, _Tp>>, _Allocator) 1573 -> map<remove_const_t<_Key>, _Tp, less<remove_const_t<_Key>>, _Allocator>; 1574#endif 1575 1576#ifndef _LIBCPP_CXX03_LANG 1577template <class _Key, class _Tp, class _Compare, class _Allocator> 1578map<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a) 1579 : __tree_(_VSTD::move(__m.__tree_), typename __base::allocator_type(__a)) 1580{ 1581 if (__a != __m.get_allocator()) 1582 { 1583 const_iterator __e = cend(); 1584 while (!__m.empty()) 1585 __tree_.__insert_unique(__e.__i_, 1586 __m.__tree_.remove(__m.begin().__i_)->__value_.__move()); 1587 } 1588} 1589 1590template <class _Key, class _Tp, class _Compare, class _Allocator> 1591_Tp& 1592map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k) 1593{ 1594 return __tree_.__emplace_unique_key_args(__k, 1595 _VSTD::piecewise_construct, 1596 _VSTD::forward_as_tuple(__k), 1597 _VSTD::forward_as_tuple()).first->__get_value().second; 1598} 1599 1600template <class _Key, class _Tp, class _Compare, class _Allocator> 1601_Tp& 1602map<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k) 1603{ 1604 return __tree_.__emplace_unique_key_args(__k, 1605 _VSTD::piecewise_construct, 1606 _VSTD::forward_as_tuple(_VSTD::move(__k)), 1607 _VSTD::forward_as_tuple()).first->__get_value().second; 1608} 1609 1610#else // _LIBCPP_CXX03_LANG 1611 1612template <class _Key, class _Tp, class _Compare, class _Allocator> 1613typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder 1614map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(const key_type& __k) 1615{ 1616 __node_allocator& __na = __tree_.__node_alloc(); 1617 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); 1618 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().first), __k); 1619 __h.get_deleter().__first_constructed = true; 1620 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().second)); 1621 __h.get_deleter().__second_constructed = true; 1622 return __h; 1623} 1624 1625template <class _Key, class _Tp, class _Compare, class _Allocator> 1626_Tp& 1627map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k) 1628{ 1629 __parent_pointer __parent; 1630 __node_base_pointer& __child = __tree_.__find_equal(__parent, __k); 1631 __node_pointer __r = static_cast<__node_pointer>(__child); 1632 if (__child == nullptr) 1633 { 1634 __node_holder __h = __construct_node_with_key(__k); 1635 __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); 1636 __r = __h.release(); 1637 } 1638 return __r->__value_.__get_value().second; 1639} 1640 1641#endif // _LIBCPP_CXX03_LANG 1642 1643template <class _Key, class _Tp, class _Compare, class _Allocator> 1644_Tp& 1645map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) 1646{ 1647 __parent_pointer __parent; 1648 __node_base_pointer& __child = __tree_.__find_equal(__parent, __k); 1649 if (__child == nullptr) 1650 __throw_out_of_range("map::at: key not found"); 1651 return static_cast<__node_pointer>(__child)->__value_.__get_value().second; 1652} 1653 1654template <class _Key, class _Tp, class _Compare, class _Allocator> 1655const _Tp& 1656map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const 1657{ 1658 __parent_pointer __parent; 1659 __node_base_pointer __child = __tree_.__find_equal(__parent, __k); 1660 if (__child == nullptr) 1661 __throw_out_of_range("map::at: key not found"); 1662 return static_cast<__node_pointer>(__child)->__value_.__get_value().second; 1663} 1664 1665 1666template <class _Key, class _Tp, class _Compare, class _Allocator> 1667inline _LIBCPP_INLINE_VISIBILITY 1668bool 1669operator==(const map<_Key, _Tp, _Compare, _Allocator>& __x, 1670 const map<_Key, _Tp, _Compare, _Allocator>& __y) 1671{ 1672 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin()); 1673} 1674 1675template <class _Key, class _Tp, class _Compare, class _Allocator> 1676inline _LIBCPP_INLINE_VISIBILITY 1677bool 1678operator< (const map<_Key, _Tp, _Compare, _Allocator>& __x, 1679 const map<_Key, _Tp, _Compare, _Allocator>& __y) 1680{ 1681 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); 1682} 1683 1684template <class _Key, class _Tp, class _Compare, class _Allocator> 1685inline _LIBCPP_INLINE_VISIBILITY 1686bool 1687operator!=(const map<_Key, _Tp, _Compare, _Allocator>& __x, 1688 const map<_Key, _Tp, _Compare, _Allocator>& __y) 1689{ 1690 return !(__x == __y); 1691} 1692 1693template <class _Key, class _Tp, class _Compare, class _Allocator> 1694inline _LIBCPP_INLINE_VISIBILITY 1695bool 1696operator> (const map<_Key, _Tp, _Compare, _Allocator>& __x, 1697 const map<_Key, _Tp, _Compare, _Allocator>& __y) 1698{ 1699 return __y < __x; 1700} 1701 1702template <class _Key, class _Tp, class _Compare, class _Allocator> 1703inline _LIBCPP_INLINE_VISIBILITY 1704bool 1705operator>=(const map<_Key, _Tp, _Compare, _Allocator>& __x, 1706 const map<_Key, _Tp, _Compare, _Allocator>& __y) 1707{ 1708 return !(__x < __y); 1709} 1710 1711template <class _Key, class _Tp, class _Compare, class _Allocator> 1712inline _LIBCPP_INLINE_VISIBILITY 1713bool 1714operator<=(const map<_Key, _Tp, _Compare, _Allocator>& __x, 1715 const map<_Key, _Tp, _Compare, _Allocator>& __y) 1716{ 1717 return !(__y < __x); 1718} 1719 1720template <class _Key, class _Tp, class _Compare, class _Allocator> 1721inline _LIBCPP_INLINE_VISIBILITY 1722void 1723swap(map<_Key, _Tp, _Compare, _Allocator>& __x, 1724 map<_Key, _Tp, _Compare, _Allocator>& __y) 1725 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) 1726{ 1727 __x.swap(__y); 1728} 1729 1730#if _LIBCPP_STD_VER > 17 1731template <class _Key, class _Tp, class _Compare, class _Allocator, 1732 class _Predicate> 1733inline _LIBCPP_INLINE_VISIBILITY 1734 typename map<_Key, _Tp, _Compare, _Allocator>::size_type 1735 erase_if(map<_Key, _Tp, _Compare, _Allocator>& __c, _Predicate __pred) { 1736 return _VSTD::__libcpp_erase_if_container(__c, __pred); 1737} 1738#endif 1739 1740 1741template <class _Key, class _Tp, class _Compare = less<_Key>, 1742 class _Allocator = allocator<pair<const _Key, _Tp> > > 1743class _LIBCPP_TEMPLATE_VIS multimap 1744{ 1745public: 1746 // types: 1747 typedef _Key key_type; 1748 typedef _Tp mapped_type; 1749 typedef pair<const key_type, mapped_type> value_type; 1750 typedef __type_identity_t<_Compare> key_compare; 1751 typedef __type_identity_t<_Allocator> allocator_type; 1752 typedef value_type& reference; 1753 typedef const value_type& const_reference; 1754 1755 static_assert((is_same<typename allocator_type::value_type, value_type>::value), 1756 "Allocator::value_type must be same type as value_type"); 1757 1758 class _LIBCPP_TEMPLATE_VIS value_compare 1759 : public __binary_function<value_type, value_type, bool> 1760 { 1761 friend class multimap; 1762 protected: 1763 key_compare comp; 1764 1765 _LIBCPP_INLINE_VISIBILITY 1766 value_compare(key_compare c) : comp(c) {} 1767 public: 1768 _LIBCPP_INLINE_VISIBILITY 1769 bool operator()(const value_type& __x, const value_type& __y) const 1770 {return comp(__x.first, __y.first);} 1771 }; 1772 1773private: 1774 1775 typedef _VSTD::__value_type<key_type, mapped_type> __value_type; 1776 typedef __map_value_compare<key_type, __value_type, key_compare> __vc; 1777 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>, 1778 __value_type>::type __allocator_type; 1779 typedef __tree<__value_type, __vc, __allocator_type> __base; 1780 typedef typename __base::__node_traits __node_traits; 1781 typedef allocator_traits<allocator_type> __alloc_traits; 1782 1783 __base __tree_; 1784 1785public: 1786 typedef typename __alloc_traits::pointer pointer; 1787 typedef typename __alloc_traits::const_pointer const_pointer; 1788 typedef typename __alloc_traits::size_type size_type; 1789 typedef typename __alloc_traits::difference_type difference_type; 1790 typedef __map_iterator<typename __base::iterator> iterator; 1791 typedef __map_const_iterator<typename __base::const_iterator> const_iterator; 1792 typedef _VSTD::reverse_iterator<iterator> reverse_iterator; 1793 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; 1794 1795#if _LIBCPP_STD_VER > 14 1796 typedef __map_node_handle<typename __base::__node, allocator_type> node_type; 1797#endif 1798 1799 template <class _Key2, class _Value2, class _Comp2, class _Alloc2> 1800 friend class _LIBCPP_TEMPLATE_VIS map; 1801 template <class _Key2, class _Value2, class _Comp2, class _Alloc2> 1802 friend class _LIBCPP_TEMPLATE_VIS multimap; 1803 1804 _LIBCPP_INLINE_VISIBILITY 1805 multimap() 1806 _NOEXCEPT_( 1807 is_nothrow_default_constructible<allocator_type>::value && 1808 is_nothrow_default_constructible<key_compare>::value && 1809 is_nothrow_copy_constructible<key_compare>::value) 1810 : __tree_(__vc(key_compare())) {} 1811 1812 _LIBCPP_INLINE_VISIBILITY 1813 explicit multimap(const key_compare& __comp) 1814 _NOEXCEPT_( 1815 is_nothrow_default_constructible<allocator_type>::value && 1816 is_nothrow_copy_constructible<key_compare>::value) 1817 : __tree_(__vc(__comp)) {} 1818 1819 _LIBCPP_INLINE_VISIBILITY 1820 explicit multimap(const key_compare& __comp, const allocator_type& __a) 1821 : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {} 1822 1823 template <class _InputIterator> 1824 _LIBCPP_INLINE_VISIBILITY 1825 multimap(_InputIterator __f, _InputIterator __l, 1826 const key_compare& __comp = key_compare()) 1827 : __tree_(__vc(__comp)) 1828 { 1829 insert(__f, __l); 1830 } 1831 1832 template <class _InputIterator> 1833 _LIBCPP_INLINE_VISIBILITY 1834 multimap(_InputIterator __f, _InputIterator __l, 1835 const key_compare& __comp, const allocator_type& __a) 1836 : __tree_(__vc(__comp), typename __base::allocator_type(__a)) 1837 { 1838 insert(__f, __l); 1839 } 1840 1841#if _LIBCPP_STD_VER > 11 1842 template <class _InputIterator> 1843 _LIBCPP_INLINE_VISIBILITY 1844 multimap(_InputIterator __f, _InputIterator __l, const allocator_type& __a) 1845 : multimap(__f, __l, key_compare(), __a) {} 1846#endif 1847 1848 _LIBCPP_INLINE_VISIBILITY 1849 multimap(const multimap& __m) 1850 : __tree_(__m.__tree_.value_comp(), 1851 __alloc_traits::select_on_container_copy_construction(__m.__tree_.__alloc())) 1852 { 1853 insert(__m.begin(), __m.end()); 1854 } 1855 1856 _LIBCPP_INLINE_VISIBILITY 1857 multimap& operator=(const multimap& __m) 1858 { 1859#ifndef _LIBCPP_CXX03_LANG 1860 __tree_ = __m.__tree_; 1861#else 1862 if (this != _VSTD::addressof(__m)) { 1863 __tree_.clear(); 1864 __tree_.value_comp() = __m.__tree_.value_comp(); 1865 __tree_.__copy_assign_alloc(__m.__tree_); 1866 insert(__m.begin(), __m.end()); 1867 } 1868#endif 1869 return *this; 1870 } 1871 1872#ifndef _LIBCPP_CXX03_LANG 1873 1874 _LIBCPP_INLINE_VISIBILITY 1875 multimap(multimap&& __m) 1876 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value) 1877 : __tree_(_VSTD::move(__m.__tree_)) 1878 { 1879 } 1880 1881 multimap(multimap&& __m, const allocator_type& __a); 1882 1883 _LIBCPP_INLINE_VISIBILITY 1884 multimap& operator=(multimap&& __m) 1885 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value) 1886 { 1887 __tree_ = _VSTD::move(__m.__tree_); 1888 return *this; 1889 } 1890 1891 _LIBCPP_INLINE_VISIBILITY 1892 multimap(initializer_list<value_type> __il, const key_compare& __comp = key_compare()) 1893 : __tree_(__vc(__comp)) 1894 { 1895 insert(__il.begin(), __il.end()); 1896 } 1897 1898 _LIBCPP_INLINE_VISIBILITY 1899 multimap(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a) 1900 : __tree_(__vc(__comp), typename __base::allocator_type(__a)) 1901 { 1902 insert(__il.begin(), __il.end()); 1903 } 1904 1905#if _LIBCPP_STD_VER > 11 1906 _LIBCPP_INLINE_VISIBILITY 1907 multimap(initializer_list<value_type> __il, const allocator_type& __a) 1908 : multimap(__il, key_compare(), __a) {} 1909#endif 1910 1911 _LIBCPP_INLINE_VISIBILITY 1912 multimap& operator=(initializer_list<value_type> __il) 1913 { 1914 __tree_.__assign_multi(__il.begin(), __il.end()); 1915 return *this; 1916 } 1917 1918#endif // _LIBCPP_CXX03_LANG 1919 1920 _LIBCPP_INLINE_VISIBILITY 1921 explicit multimap(const allocator_type& __a) 1922 : __tree_(typename __base::allocator_type(__a)) 1923 { 1924 } 1925 1926 _LIBCPP_INLINE_VISIBILITY 1927 multimap(const multimap& __m, const allocator_type& __a) 1928 : __tree_(__m.__tree_.value_comp(), typename __base::allocator_type(__a)) 1929 { 1930 insert(__m.begin(), __m.end()); 1931 } 1932 1933 _LIBCPP_INLINE_VISIBILITY 1934 ~multimap() { 1935 static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), ""); 1936 } 1937 1938 _LIBCPP_INLINE_VISIBILITY 1939 iterator begin() _NOEXCEPT {return __tree_.begin();} 1940 _LIBCPP_INLINE_VISIBILITY 1941 const_iterator begin() const _NOEXCEPT {return __tree_.begin();} 1942 _LIBCPP_INLINE_VISIBILITY 1943 iterator end() _NOEXCEPT {return __tree_.end();} 1944 _LIBCPP_INLINE_VISIBILITY 1945 const_iterator end() const _NOEXCEPT {return __tree_.end();} 1946 1947 _LIBCPP_INLINE_VISIBILITY 1948 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());} 1949 _LIBCPP_INLINE_VISIBILITY 1950 const_reverse_iterator rbegin() const _NOEXCEPT 1951 {return const_reverse_iterator(end());} 1952 _LIBCPP_INLINE_VISIBILITY 1953 reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());} 1954 _LIBCPP_INLINE_VISIBILITY 1955 const_reverse_iterator rend() const _NOEXCEPT 1956 {return const_reverse_iterator(begin());} 1957 1958 _LIBCPP_INLINE_VISIBILITY 1959 const_iterator cbegin() const _NOEXCEPT {return begin();} 1960 _LIBCPP_INLINE_VISIBILITY 1961 const_iterator cend() const _NOEXCEPT {return end();} 1962 _LIBCPP_INLINE_VISIBILITY 1963 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();} 1964 _LIBCPP_INLINE_VISIBILITY 1965 const_reverse_iterator crend() const _NOEXCEPT {return rend();} 1966 1967 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 1968 bool empty() const _NOEXCEPT {return __tree_.size() == 0;} 1969 _LIBCPP_INLINE_VISIBILITY 1970 size_type size() const _NOEXCEPT {return __tree_.size();} 1971 _LIBCPP_INLINE_VISIBILITY 1972 size_type max_size() const _NOEXCEPT {return __tree_.max_size();} 1973 1974 _LIBCPP_INLINE_VISIBILITY 1975 allocator_type get_allocator() const _NOEXCEPT {return allocator_type(__tree_.__alloc());} 1976 _LIBCPP_INLINE_VISIBILITY 1977 key_compare key_comp() const {return __tree_.value_comp().key_comp();} 1978 _LIBCPP_INLINE_VISIBILITY 1979 value_compare value_comp() const 1980 {return value_compare(__tree_.value_comp().key_comp());} 1981 1982#ifndef _LIBCPP_CXX03_LANG 1983 1984 template <class ..._Args> 1985 _LIBCPP_INLINE_VISIBILITY 1986 iterator emplace(_Args&& ...__args) { 1987 return __tree_.__emplace_multi(_VSTD::forward<_Args>(__args)...); 1988 } 1989 1990 template <class ..._Args> 1991 _LIBCPP_INLINE_VISIBILITY 1992 iterator emplace_hint(const_iterator __p, _Args&& ...__args) { 1993 return __tree_.__emplace_hint_multi(__p.__i_, _VSTD::forward<_Args>(__args)...); 1994 } 1995 1996 template <class _Pp, 1997 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type> 1998 _LIBCPP_INLINE_VISIBILITY 1999 iterator insert(_Pp&& __p) 2000 {return __tree_.__insert_multi(_VSTD::forward<_Pp>(__p));} 2001 2002 template <class _Pp, 2003 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type> 2004 _LIBCPP_INLINE_VISIBILITY 2005 iterator insert(const_iterator __pos, _Pp&& __p) 2006 {return __tree_.__insert_multi(__pos.__i_, _VSTD::forward<_Pp>(__p));} 2007 2008 _LIBCPP_INLINE_VISIBILITY 2009 iterator insert(value_type&& __v) 2010 {return __tree_.__insert_multi(_VSTD::move(__v));} 2011 2012 _LIBCPP_INLINE_VISIBILITY 2013 iterator insert(const_iterator __p, value_type&& __v) 2014 {return __tree_.__insert_multi(__p.__i_, _VSTD::move(__v));} 2015 2016 2017 _LIBCPP_INLINE_VISIBILITY 2018 void insert(initializer_list<value_type> __il) 2019 {insert(__il.begin(), __il.end());} 2020 2021#endif // _LIBCPP_CXX03_LANG 2022 2023 _LIBCPP_INLINE_VISIBILITY 2024 iterator insert(const value_type& __v) {return __tree_.__insert_multi(__v);} 2025 2026 _LIBCPP_INLINE_VISIBILITY 2027 iterator insert(const_iterator __p, const value_type& __v) 2028 {return __tree_.__insert_multi(__p.__i_, __v);} 2029 2030 template <class _InputIterator> 2031 _LIBCPP_INLINE_VISIBILITY 2032 void insert(_InputIterator __f, _InputIterator __l) 2033 { 2034 for (const_iterator __e = cend(); __f != __l; ++__f) 2035 __tree_.__insert_multi(__e.__i_, *__f); 2036 } 2037 2038 _LIBCPP_INLINE_VISIBILITY 2039 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);} 2040 _LIBCPP_INLINE_VISIBILITY 2041 iterator erase(iterator __p) {return __tree_.erase(__p.__i_);} 2042 _LIBCPP_INLINE_VISIBILITY 2043 size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);} 2044 _LIBCPP_INLINE_VISIBILITY 2045 iterator erase(const_iterator __f, const_iterator __l) 2046 {return __tree_.erase(__f.__i_, __l.__i_);} 2047 2048#if _LIBCPP_STD_VER > 14 2049 _LIBCPP_INLINE_VISIBILITY 2050 iterator insert(node_type&& __nh) 2051 { 2052 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(), 2053 "node_type with incompatible allocator passed to multimap::insert()"); 2054 return __tree_.template __node_handle_insert_multi<node_type>( 2055 _VSTD::move(__nh)); 2056 } 2057 _LIBCPP_INLINE_VISIBILITY 2058 iterator insert(const_iterator __hint, node_type&& __nh) 2059 { 2060 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(), 2061 "node_type with incompatible allocator passed to multimap::insert()"); 2062 return __tree_.template __node_handle_insert_multi<node_type>( 2063 __hint.__i_, _VSTD::move(__nh)); 2064 } 2065 _LIBCPP_INLINE_VISIBILITY 2066 node_type extract(key_type const& __key) 2067 { 2068 return __tree_.template __node_handle_extract<node_type>(__key); 2069 } 2070 _LIBCPP_INLINE_VISIBILITY 2071 node_type extract(const_iterator __it) 2072 { 2073 return __tree_.template __node_handle_extract<node_type>( 2074 __it.__i_); 2075 } 2076 template <class _Compare2> 2077 _LIBCPP_INLINE_VISIBILITY 2078 void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>& __source) 2079 { 2080 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), 2081 "merging container with incompatible allocator"); 2082 return __tree_.__node_handle_merge_multi(__source.__tree_); 2083 } 2084 template <class _Compare2> 2085 _LIBCPP_INLINE_VISIBILITY 2086 void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>&& __source) 2087 { 2088 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), 2089 "merging container with incompatible allocator"); 2090 return __tree_.__node_handle_merge_multi(__source.__tree_); 2091 } 2092 template <class _Compare2> 2093 _LIBCPP_INLINE_VISIBILITY 2094 void merge(map<key_type, mapped_type, _Compare2, allocator_type>& __source) 2095 { 2096 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), 2097 "merging container with incompatible allocator"); 2098 return __tree_.__node_handle_merge_multi(__source.__tree_); 2099 } 2100 template <class _Compare2> 2101 _LIBCPP_INLINE_VISIBILITY 2102 void merge(map<key_type, mapped_type, _Compare2, allocator_type>&& __source) 2103 { 2104 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), 2105 "merging container with incompatible allocator"); 2106 return __tree_.__node_handle_merge_multi(__source.__tree_); 2107 } 2108#endif 2109 2110 _LIBCPP_INLINE_VISIBILITY 2111 void clear() _NOEXCEPT {__tree_.clear();} 2112 2113 _LIBCPP_INLINE_VISIBILITY 2114 void swap(multimap& __m) 2115 _NOEXCEPT_(__is_nothrow_swappable<__base>::value) 2116 {__tree_.swap(__m.__tree_);} 2117 2118 _LIBCPP_INLINE_VISIBILITY 2119 iterator find(const key_type& __k) {return __tree_.find(__k);} 2120 _LIBCPP_INLINE_VISIBILITY 2121 const_iterator find(const key_type& __k) const {return __tree_.find(__k);} 2122#if _LIBCPP_STD_VER > 11 2123 template <typename _K2> 2124 _LIBCPP_INLINE_VISIBILITY 2125 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type 2126 find(const _K2& __k) {return __tree_.find(__k);} 2127 template <typename _K2> 2128 _LIBCPP_INLINE_VISIBILITY 2129 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type 2130 find(const _K2& __k) const {return __tree_.find(__k);} 2131#endif 2132 2133 _LIBCPP_INLINE_VISIBILITY 2134 size_type count(const key_type& __k) const 2135 {return __tree_.__count_multi(__k);} 2136#if _LIBCPP_STD_VER > 11 2137 template <typename _K2> 2138 _LIBCPP_INLINE_VISIBILITY 2139 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type 2140 count(const _K2& __k) const {return __tree_.__count_multi(__k);} 2141#endif 2142 2143#if _LIBCPP_STD_VER > 17 2144 _LIBCPP_INLINE_VISIBILITY 2145 bool contains(const key_type& __k) const {return find(__k) != end();} 2146 template <typename _K2> 2147 _LIBCPP_INLINE_VISIBILITY 2148 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type 2149 contains(const _K2& __k) const { return find(__k) != end(); } 2150#endif // _LIBCPP_STD_VER > 17 2151 2152 _LIBCPP_INLINE_VISIBILITY 2153 iterator lower_bound(const key_type& __k) 2154 {return __tree_.lower_bound(__k);} 2155 _LIBCPP_INLINE_VISIBILITY 2156 const_iterator lower_bound(const key_type& __k) const 2157 {return __tree_.lower_bound(__k);} 2158#if _LIBCPP_STD_VER > 11 2159 template <typename _K2> 2160 _LIBCPP_INLINE_VISIBILITY 2161 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type 2162 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);} 2163 2164 template <typename _K2> 2165 _LIBCPP_INLINE_VISIBILITY 2166 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type 2167 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);} 2168#endif 2169 2170 _LIBCPP_INLINE_VISIBILITY 2171 iterator upper_bound(const key_type& __k) 2172 {return __tree_.upper_bound(__k);} 2173 _LIBCPP_INLINE_VISIBILITY 2174 const_iterator upper_bound(const key_type& __k) const 2175 {return __tree_.upper_bound(__k);} 2176#if _LIBCPP_STD_VER > 11 2177 template <typename _K2> 2178 _LIBCPP_INLINE_VISIBILITY 2179 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type 2180 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);} 2181 template <typename _K2> 2182 _LIBCPP_INLINE_VISIBILITY 2183 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type 2184 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);} 2185#endif 2186 2187 _LIBCPP_INLINE_VISIBILITY 2188 pair<iterator,iterator> equal_range(const key_type& __k) 2189 {return __tree_.__equal_range_multi(__k);} 2190 _LIBCPP_INLINE_VISIBILITY 2191 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const 2192 {return __tree_.__equal_range_multi(__k);} 2193#if _LIBCPP_STD_VER > 11 2194 template <typename _K2> 2195 _LIBCPP_INLINE_VISIBILITY 2196 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type 2197 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);} 2198 template <typename _K2> 2199 _LIBCPP_INLINE_VISIBILITY 2200 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type 2201 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);} 2202#endif 2203 2204private: 2205 typedef typename __base::__node __node; 2206 typedef typename __base::__node_allocator __node_allocator; 2207 typedef typename __base::__node_pointer __node_pointer; 2208 2209 typedef __map_node_destructor<__node_allocator> _Dp; 2210 typedef unique_ptr<__node, _Dp> __node_holder; 2211}; 2212 2213#if _LIBCPP_STD_VER >= 17 2214template<class _InputIterator, class _Compare = less<__iter_key_type<_InputIterator>>, 2215 class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>, 2216 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value, void>, 2217 class = enable_if_t<!__is_allocator<_Compare>::value, void>, 2218 class = enable_if_t<__is_allocator<_Allocator>::value, void>> 2219multimap(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator()) 2220 -> multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Compare, _Allocator>; 2221 2222template<class _Key, class _Tp, class _Compare = less<remove_const_t<_Key>>, 2223 class _Allocator = allocator<pair<const _Key, _Tp>>, 2224 class = enable_if_t<!__is_allocator<_Compare>::value, void>, 2225 class = enable_if_t<__is_allocator<_Allocator>::value, void>> 2226multimap(initializer_list<pair<_Key, _Tp>>, _Compare = _Compare(), _Allocator = _Allocator()) 2227 -> multimap<remove_const_t<_Key>, _Tp, _Compare, _Allocator>; 2228 2229template<class _InputIterator, class _Allocator, 2230 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value, void>, 2231 class = enable_if_t<__is_allocator<_Allocator>::value, void>> 2232multimap(_InputIterator, _InputIterator, _Allocator) 2233 -> multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, 2234 less<__iter_key_type<_InputIterator>>, _Allocator>; 2235 2236template<class _Key, class _Tp, class _Allocator, 2237 class = enable_if_t<__is_allocator<_Allocator>::value, void>> 2238multimap(initializer_list<pair<_Key, _Tp>>, _Allocator) 2239 -> multimap<remove_const_t<_Key>, _Tp, less<remove_const_t<_Key>>, _Allocator>; 2240#endif 2241 2242#ifndef _LIBCPP_CXX03_LANG 2243template <class _Key, class _Tp, class _Compare, class _Allocator> 2244multimap<_Key, _Tp, _Compare, _Allocator>::multimap(multimap&& __m, const allocator_type& __a) 2245 : __tree_(_VSTD::move(__m.__tree_), typename __base::allocator_type(__a)) 2246{ 2247 if (__a != __m.get_allocator()) 2248 { 2249 const_iterator __e = cend(); 2250 while (!__m.empty()) 2251 __tree_.__insert_multi(__e.__i_, 2252 _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_.__move())); 2253 } 2254} 2255#endif 2256 2257template <class _Key, class _Tp, class _Compare, class _Allocator> 2258inline _LIBCPP_INLINE_VISIBILITY 2259bool 2260operator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __x, 2261 const multimap<_Key, _Tp, _Compare, _Allocator>& __y) 2262{ 2263 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin()); 2264} 2265 2266template <class _Key, class _Tp, class _Compare, class _Allocator> 2267inline _LIBCPP_INLINE_VISIBILITY 2268bool 2269operator< (const multimap<_Key, _Tp, _Compare, _Allocator>& __x, 2270 const multimap<_Key, _Tp, _Compare, _Allocator>& __y) 2271{ 2272 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); 2273} 2274 2275template <class _Key, class _Tp, class _Compare, class _Allocator> 2276inline _LIBCPP_INLINE_VISIBILITY 2277bool 2278operator!=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x, 2279 const multimap<_Key, _Tp, _Compare, _Allocator>& __y) 2280{ 2281 return !(__x == __y); 2282} 2283 2284template <class _Key, class _Tp, class _Compare, class _Allocator> 2285inline _LIBCPP_INLINE_VISIBILITY 2286bool 2287operator> (const multimap<_Key, _Tp, _Compare, _Allocator>& __x, 2288 const multimap<_Key, _Tp, _Compare, _Allocator>& __y) 2289{ 2290 return __y < __x; 2291} 2292 2293template <class _Key, class _Tp, class _Compare, class _Allocator> 2294inline _LIBCPP_INLINE_VISIBILITY 2295bool 2296operator>=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x, 2297 const multimap<_Key, _Tp, _Compare, _Allocator>& __y) 2298{ 2299 return !(__x < __y); 2300} 2301 2302template <class _Key, class _Tp, class _Compare, class _Allocator> 2303inline _LIBCPP_INLINE_VISIBILITY 2304bool 2305operator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x, 2306 const multimap<_Key, _Tp, _Compare, _Allocator>& __y) 2307{ 2308 return !(__y < __x); 2309} 2310 2311template <class _Key, class _Tp, class _Compare, class _Allocator> 2312inline _LIBCPP_INLINE_VISIBILITY 2313void 2314swap(multimap<_Key, _Tp, _Compare, _Allocator>& __x, 2315 multimap<_Key, _Tp, _Compare, _Allocator>& __y) 2316 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) 2317{ 2318 __x.swap(__y); 2319} 2320 2321#if _LIBCPP_STD_VER > 17 2322template <class _Key, class _Tp, class _Compare, class _Allocator, 2323 class _Predicate> 2324inline _LIBCPP_INLINE_VISIBILITY 2325 typename multimap<_Key, _Tp, _Compare, _Allocator>::size_type 2326 erase_if(multimap<_Key, _Tp, _Compare, _Allocator>& __c, 2327 _Predicate __pred) { 2328 return _VSTD::__libcpp_erase_if_container(__c, __pred); 2329} 2330#endif 2331 2332_LIBCPP_END_NAMESPACE_STD 2333 2334#endif // _LIBCPP_MAP 2335