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