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