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