| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | #ifndef _STL_MAP_H |
| 57 | #define _STL_MAP_H 1 |
| 58 | |
| 59 | #include <bits/functexcept.h> |
| 60 | #include <bits/concept_check.h> |
| 61 | #if __cplusplus >= 201103L |
| 62 | #include <initializer_list> |
| 63 | #include <tuple> |
| 64 | #endif |
| 65 | |
| 66 | namespace std _GLIBCXX_VISIBILITY(default) |
| 67 | { |
| 68 | _GLIBCXX_BEGIN_NAMESPACE_CONTAINER |
| 69 | |
| 70 | template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> |
| 71 | class multimap; |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | template <typename _Key, typename _Tp, typename _Compare = std::less<_Key>, |
| 98 | typename _Alloc = std::allocator<std::pair<const _Key, _Tp> > > |
| 99 | class map |
| 100 | { |
| 101 | public: |
| 102 | typedef _Key key_type; |
| 103 | typedef _Tp mapped_type; |
| 104 | typedef std::pair<const _Key, _Tp> value_type; |
| 105 | typedef _Compare key_compare; |
| 106 | typedef _Alloc allocator_type; |
| 107 | |
| 108 | private: |
| 109 | #ifdef _GLIBCXX_CONCEPT_CHECKS |
| 110 | |
| 111 | typedef typename _Alloc::value_type _Alloc_value_type; |
| 112 | # if __cplusplus < 201103L |
| 113 | __glibcxx_class_requires(_Tp, _SGIAssignableConcept) |
| 114 | # endif |
| 115 | __glibcxx_class_requires4(_Compare, bool, _Key, _Key, |
| 116 | _BinaryFunctionConcept) |
| 117 | __glibcxx_class_requires2(value_type, _Alloc_value_type, _SameTypeConcept) |
| 118 | #endif |
| 119 | |
| 120 | public: |
| 121 | class value_compare |
| 122 | : public std::binary_function<value_type, value_type, bool> |
| 123 | { |
| 124 | friend class map<_Key, _Tp, _Compare, _Alloc>; |
| 125 | protected: |
| 126 | _Compare comp; |
| 127 | |
| 128 | value_compare(_Compare __c) |
| 129 | : comp(__c) { } |
| 130 | |
| 131 | public: |
| 132 | bool operator()(const value_type& __x, const value_type& __y) const |
| 133 | { return comp(__x.first, __y.first); } |
| 134 | }; |
| 135 | |
| 136 | private: |
| 137 | |
| 138 | typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template |
| 139 | rebind<value_type>::other _Pair_alloc_type; |
| 140 | |
| 141 | typedef _Rb_tree<key_type, value_type, _Select1st<value_type>, |
| 142 | key_compare, _Pair_alloc_type> _Rep_type; |
| 143 | |
| 144 | |
| 145 | _Rep_type _M_t; |
| 146 | |
| 147 | typedef __gnu_cxx::__alloc_traits<_Pair_alloc_type> _Alloc_traits; |
| 148 | |
| 149 | public: |
| 150 | |
| 151 | |
| 152 | typedef typename _Alloc_traits::pointer pointer; |
| 153 | typedef typename _Alloc_traits::const_pointer const_pointer; |
| 154 | typedef typename _Alloc_traits::reference reference; |
| 155 | typedef typename _Alloc_traits::const_reference const_reference; |
| 156 | typedef typename _Rep_type::iterator iterator; |
| 157 | typedef typename _Rep_type::const_iterator const_iterator; |
| 158 | typedef typename _Rep_type::size_type size_type; |
| 159 | typedef typename _Rep_type::difference_type difference_type; |
| 160 | typedef typename _Rep_type::reverse_iterator reverse_iterator; |
| 161 | typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator; |
| 162 | |
| 163 | #if __cplusplus > 201402L |
| 164 | using node_type = typename _Rep_type::node_type; |
| 165 | using insert_return_type = typename _Rep_type::insert_return_type; |
| 166 | #endif |
| 167 | |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | #if __cplusplus < 201103L |
| 175 | map() : _M_t() { } |
| 176 | #else |
| 177 | map() = default; |
| 178 | #endif |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | explicit |
| 186 | map(const _Compare& __comp, |
| 187 | const allocator_type& __a = allocator_type()) |
| 188 | : _M_t(__comp, _Pair_alloc_type(__a)) { } |
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | #if __cplusplus < 201103L |
| 196 | map(const map& __x) |
| 197 | : _M_t(__x._M_t) { } |
| 198 | #else |
| 199 | map(const map&) = default; |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | map(map&&) = default; |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | |
| 214 | |
| 215 | |
| 216 | |
| 217 | |
| 218 | |
| 219 | |
| 220 | map(initializer_list<value_type> __l, |
| 221 | const _Compare& __comp = _Compare(), |
| 222 | const allocator_type& __a = allocator_type()) |
| 223 | : _M_t(__comp, _Pair_alloc_type(__a)) |
| 224 | { _M_t._M_insert_unique(__l.begin(), __l.end()); } |
| 225 | |
| 226 | |
| 227 | explicit |
| 228 | map(const allocator_type& __a) |
| 229 | : _M_t(_Compare(), _Pair_alloc_type(__a)) { } |
| 230 | |
| 231 | |
| 232 | map(const map& __m, const allocator_type& __a) |
| 233 | : _M_t(__m._M_t, _Pair_alloc_type(__a)) { } |
| 234 | |
| 235 | |
| 236 | map(map&& __m, const allocator_type& __a) |
| 237 | noexcept(is_nothrow_copy_constructible<_Compare>::value |
| 238 | && _Alloc_traits::_S_always_equal()) |
| 239 | : _M_t(std::move(__m._M_t), _Pair_alloc_type(__a)) { } |
| 240 | |
| 241 | |
| 242 | map(initializer_list<value_type> __l, const allocator_type& __a) |
| 243 | : _M_t(_Compare(), _Pair_alloc_type(__a)) |
| 244 | { _M_t._M_insert_unique(__l.begin(), __l.end()); } |
| 245 | |
| 246 | |
| 247 | template<typename _InputIterator> |
| 248 | map(_InputIterator __first, _InputIterator __last, |
| 249 | const allocator_type& __a) |
| 250 | : _M_t(_Compare(), _Pair_alloc_type(__a)) |
| 251 | { _M_t._M_insert_unique(__first, __last); } |
| 252 | #endif |
| 253 | |
| 254 | |
| 255 | |
| 256 | |
| 257 | |
| 258 | |
| 259 | |
| 260 | |
| 261 | |
| 262 | |
| 263 | |
| 264 | template<typename _InputIterator> |
| 265 | map(_InputIterator __first, _InputIterator __last) |
| 266 | : _M_t() |
| 267 | { _M_t._M_insert_unique(__first, __last); } |
| 268 | |
| 269 | |
| 270 | |
| 271 | |
| 272 | |
| 273 | |
| 274 | |
| 275 | |
| 276 | |
| 277 | |
| 278 | |
| 279 | |
| 280 | |
| 281 | template<typename _InputIterator> |
| 282 | map(_InputIterator __first, _InputIterator __last, |
| 283 | const _Compare& __comp, |
| 284 | const allocator_type& __a = allocator_type()) |
| 285 | : _M_t(__comp, _Pair_alloc_type(__a)) |
| 286 | { _M_t._M_insert_unique(__first, __last); } |
| 287 | |
| 288 | #if __cplusplus >= 201103L |
| 289 | |
| 290 | |
| 291 | |
| 292 | |
| 293 | |
| 294 | ~map() = default; |
| 295 | #endif |
| 296 | |
| 297 | |
| 298 | |
| 299 | |
| 300 | |
| 301 | |
| 302 | #if __cplusplus < 201103L |
| 303 | map& |
| 304 | operator=(const map& __x) |
| 305 | { |
| 306 | _M_t = __x._M_t; |
| 307 | return *this; |
| 308 | } |
| 309 | #else |
| 310 | map& |
| 311 | operator=(const map&) = default; |
| 312 | |
| 313 | |
| 314 | map& |
| 315 | operator=(map&&) = default; |
| 316 | |
| 317 | |
| 318 | |
| 319 | |
| 320 | |
| 321 | |
| 322 | |
| 323 | |
| 324 | |
| 325 | |
| 326 | |
| 327 | |
| 328 | map& |
| 329 | operator=(initializer_list<value_type> __l) |
| 330 | { |
| 331 | _M_t._M_assign_unique(__l.begin(), __l.end()); |
| 332 | return *this; |
| 333 | } |
| 334 | #endif |
| 335 | |
| 336 | |
| 337 | allocator_type |
| 338 | get_allocator() const _GLIBCXX_NOEXCEPT |
| 339 | { return allocator_type(_M_t.get_allocator()); } |
| 340 | |
| 341 | |
| 342 | |
| 343 | |
| 344 | |
| 345 | |
| 346 | |
| 347 | iterator |
| 348 | begin() _GLIBCXX_NOEXCEPT |
| 349 | { return _M_t.begin(); } |
| 350 | |
| 351 | |
| 352 | |
| 353 | |
| 354 | |
| 355 | |
| 356 | const_iterator |
| 357 | begin() const _GLIBCXX_NOEXCEPT |
| 358 | { return _M_t.begin(); } |
| 359 | |
| 360 | |
| 361 | |
| 362 | |
| 363 | |
| 364 | |
| 365 | iterator |
| 366 | end() _GLIBCXX_NOEXCEPT |
| 367 | { return _M_t.end(); } |
| 368 | |
| 369 | |
| 370 | |
| 371 | |
| 372 | |
| 373 | |
| 374 | const_iterator |
| 375 | end() const _GLIBCXX_NOEXCEPT |
| 376 | { return _M_t.end(); } |
| 377 | |
| 378 | |
| 379 | |
| 380 | |
| 381 | |
| 382 | |
| 383 | reverse_iterator |
| 384 | rbegin() _GLIBCXX_NOEXCEPT |
| 385 | { return _M_t.rbegin(); } |
| 386 | |
| 387 | |
| 388 | |
| 389 | |
| 390 | |
| 391 | |
| 392 | const_reverse_iterator |
| 393 | rbegin() const _GLIBCXX_NOEXCEPT |
| 394 | { return _M_t.rbegin(); } |
| 395 | |
| 396 | |
| 397 | |
| 398 | |
| 399 | |
| 400 | |
| 401 | reverse_iterator |
| 402 | rend() _GLIBCXX_NOEXCEPT |
| 403 | { return _M_t.rend(); } |
| 404 | |
| 405 | |
| 406 | |
| 407 | |
| 408 | |
| 409 | |
| 410 | const_reverse_iterator |
| 411 | rend() const _GLIBCXX_NOEXCEPT |
| 412 | { return _M_t.rend(); } |
| 413 | |
| 414 | #if __cplusplus >= 201103L |
| 415 | |
| 416 | |
| 417 | |
| 418 | |
| 419 | |
| 420 | const_iterator |
| 421 | cbegin() const noexcept |
| 422 | { return _M_t.begin(); } |
| 423 | |
| 424 | |
| 425 | |
| 426 | |
| 427 | |
| 428 | |
| 429 | const_iterator |
| 430 | cend() const noexcept |
| 431 | { return _M_t.end(); } |
| 432 | |
| 433 | |
| 434 | |
| 435 | |
| 436 | |
| 437 | |
| 438 | const_reverse_iterator |
| 439 | crbegin() const noexcept |
| 440 | { return _M_t.rbegin(); } |
| 441 | |
| 442 | |
| 443 | |
| 444 | |
| 445 | |
| 446 | |
| 447 | const_reverse_iterator |
| 448 | crend() const noexcept |
| 449 | { return _M_t.rend(); } |
| 450 | #endif |
| 451 | |
| 452 | |
| 453 | |
| 454 | |
| 455 | |
| 456 | bool |
| 457 | empty() const _GLIBCXX_NOEXCEPT |
| 458 | { return _M_t.empty(); } |
| 459 | |
| 460 | |
| 461 | size_type |
| 462 | size() const _GLIBCXX_NOEXCEPT |
| 463 | { return _M_t.size(); } |
| 464 | |
| 465 | |
| 466 | size_type |
| 467 | max_size() const _GLIBCXX_NOEXCEPT |
| 468 | { return _M_t.max_size(); } |
| 469 | |
| 470 | |
| 471 | |
| 472 | |
| 473 | |
| 474 | |
| 475 | |
| 476 | |
| 477 | |
| 478 | |
| 479 | |
| 480 | |
| 481 | |
| 482 | |
| 483 | mapped_type& |
| 484 | operator[](const key_type& __k) |
| 485 | { |
| 486 | |
| 487 | __glibcxx_function_requires(_DefaultConstructibleConcept<mapped_type>) |
| 488 | |
| 489 | iterator __i = lower_bound(__k); |
| 490 | |
| 491 | if (__i == end() || key_comp()(__k, (*__i).first)) |
| 492 | #if __cplusplus >= 201103L |
| 493 | __i = _M_t._M_emplace_hint_unique(__i, std::piecewise_construct, |
| 494 | std::tuple<const key_type&>(__k), |
| 495 | std::tuple<>()); |
| 496 | #else |
| 497 | __i = insert(__i, value_type(__k, mapped_type())); |
| 498 | #endif |
| 499 | return (*__i).second; |
| 500 | } |
| 501 | |
| 502 | #if __cplusplus >= 201103L |
| 503 | mapped_type& |
| 504 | operator[](key_type&& __k) |
| 505 | { |
| 506 | |
| 507 | __glibcxx_function_requires(_DefaultConstructibleConcept<mapped_type>) |
| 508 | |
| 509 | iterator __i = lower_bound(__k); |
| 510 | |
| 511 | if (__i == end() || key_comp()(__k, (*__i).first)) |
| 512 | __i = _M_t._M_emplace_hint_unique(__i, std::piecewise_construct, |
| 513 | std::forward_as_tuple(std::move(__k)), |
| 514 | std::tuple<>()); |
| 515 | return (*__i).second; |
| 516 | } |
| 517 | #endif |
| 518 | |
| 519 | |
| 520 | |
| 521 | |
| 522 | |
| 523 | |
| 524 | |
| 525 | |
| 526 | |
| 527 | |
| 528 | mapped_type& |
| 529 | at(const key_type& __k) |
| 530 | { |
| 531 | iterator __i = lower_bound(__k); |
| 532 | if (__i == end() || key_comp()(__k, (*__i).first)) |
| 533 | __throw_out_of_range(__N("map::at")); |
| 534 | return (*__i).second; |
| 535 | } |
| 536 | |
| 537 | const mapped_type& |
| 538 | at(const key_type& __k) const |
| 539 | { |
| 540 | const_iterator __i = lower_bound(__k); |
| 541 | if (__i == end() || key_comp()(__k, (*__i).first)) |
| 542 | __throw_out_of_range(__N("map::at")); |
| 543 | return (*__i).second; |
| 544 | } |
| 545 | |
| 546 | |
| 547 | #if __cplusplus >= 201103L |
| 548 | |
| 549 | |
| 550 | |
| 551 | |
| 552 | |
| 553 | |
| 554 | |
| 555 | |
| 556 | |
| 557 | |
| 558 | |
| 559 | |
| 560 | |
| 561 | |
| 562 | |
| 563 | |
| 564 | |
| 565 | |
| 566 | template<typename... _Args> |
| 567 | std::pair<iterator, bool> |
| 568 | emplace(_Args&&... __args) |
| 569 | { return _M_t._M_emplace_unique(std::forward<_Args>(__args)...); } |
| 570 | |
| 571 | |
| 572 | |
| 573 | |
| 574 | |
| 575 | |
| 576 | |
| 577 | |
| 578 | |
| 579 | |
| 580 | |
| 581 | |
| 582 | |
| 583 | |
| 584 | |
| 585 | |
| 586 | |
| 587 | |
| 588 | |
| 589 | |
| 590 | |
| 591 | |
| 592 | |
| 593 | |
| 594 | |
| 595 | |
| 596 | template<typename... _Args> |
| 597 | iterator |
| 598 | emplace_hint(const_iterator __pos, _Args&&... __args) |
| 599 | { |
| 600 | return _M_t._M_emplace_hint_unique(__pos, |
| 601 | std::forward<_Args>(__args)...); |
| 602 | } |
| 603 | #endif |
| 604 | |
| 605 | #if __cplusplus > 201402L |
| 606 | |
| 607 | node_type |
| 608 | extract(const_iterator __pos) |
| 609 | { |
| 610 | __glibcxx_assert(__pos != end()); |
| 611 | return _M_t.extract(__pos); |
| 612 | } |
| 613 | |
| 614 | |
| 615 | node_type |
| 616 | extract(const key_type& __x) |
| 617 | { return _M_t.extract(__x); } |
| 618 | |
| 619 | |
| 620 | insert_return_type |
| 621 | insert(node_type&& __nh) |
| 622 | { return _M_t._M_reinsert_node_unique(std::move(__nh)); } |
| 623 | |
| 624 | |
| 625 | iterator |
| 626 | insert(const_iterator __hint, node_type&& __nh) |
| 627 | { return _M_t._M_reinsert_node_hint_unique(__hint, std::move(__nh)); } |
| 628 | |
| 629 | template<typename, typename> |
| 630 | friend class _Rb_tree_merge_helper; |
| 631 | |
| 632 | template<typename _C2> |
| 633 | void |
| 634 | merge(map<_Key, _Tp, _C2, _Alloc>& __source) |
| 635 | { |
| 636 | using _Merge_helper = _Rb_tree_merge_helper<map, _C2>; |
| 637 | _M_t._M_merge_unique(_Merge_helper::_S_get_tree(__source)); |
| 638 | } |
| 639 | |
| 640 | template<typename _C2> |
| 641 | void |
| 642 | merge(map<_Key, _Tp, _C2, _Alloc>&& __source) |
| 643 | { merge(__source); } |
| 644 | |
| 645 | template<typename _C2> |
| 646 | void |
| 647 | merge(multimap<_Key, _Tp, _C2, _Alloc>& __source) |
| 648 | { |
| 649 | using _Merge_helper = _Rb_tree_merge_helper<map, _C2>; |
| 650 | _M_t._M_merge_unique(_Merge_helper::_S_get_tree(__source)); |
| 651 | } |
| 652 | |
| 653 | template<typename _C2> |
| 654 | void |
| 655 | merge(multimap<_Key, _Tp, _C2, _Alloc>&& __source) |
| 656 | { merge(__source); } |
| 657 | #endif |
| 658 | |
| 659 | #if __cplusplus > 201402L |
| 660 | #define __cpp_lib_map_try_emplace 201411 |
| 661 | |
| 662 | |
| 663 | |
| 664 | |
| 665 | |
| 666 | |
| 667 | |
| 668 | |
| 669 | |
| 670 | |
| 671 | |
| 672 | |
| 673 | |
| 674 | |
| 675 | |
| 676 | |
| 677 | |
| 678 | |
| 679 | |
| 680 | |
| 681 | template <typename... _Args> |
| 682 | pair<iterator, bool> |
| 683 | try_emplace(const key_type& __k, _Args&&... __args) |
| 684 | { |
| 685 | iterator __i = lower_bound(__k); |
| 686 | if (__i == end() || key_comp()(__k, (*__i).first)) |
| 687 | { |
| 688 | __i = emplace_hint(__i, std::piecewise_construct, |
| 689 | std::forward_as_tuple(__k), |
| 690 | std::forward_as_tuple( |
| 691 | std::forward<_Args>(__args)...)); |
| 692 | return {__i, true}; |
| 693 | } |
| 694 | return {__i, false}; |
| 695 | } |
| 696 | |
| 697 | |
| 698 | template <typename... _Args> |
| 699 | pair<iterator, bool> |
| 700 | try_emplace(key_type&& __k, _Args&&... __args) |
| 701 | { |
| 702 | iterator __i = lower_bound(__k); |
| 703 | if (__i == end() || key_comp()(__k, (*__i).first)) |
| 704 | { |
| 705 | __i = emplace_hint(__i, std::piecewise_construct, |
| 706 | std::forward_as_tuple(std::move(__k)), |
| 707 | std::forward_as_tuple( |
| 708 | std::forward<_Args>(__args)...)); |
| 709 | return {__i, true}; |
| 710 | } |
| 711 | return {__i, false}; |
| 712 | } |
| 713 | |
| 714 | |
| 715 | |
| 716 | |
| 717 | |
| 718 | |
| 719 | |
| 720 | |
| 721 | |
| 722 | |
| 723 | |
| 724 | |
| 725 | |
| 726 | |
| 727 | |
| 728 | |
| 729 | |
| 730 | |
| 731 | |
| 732 | |
| 733 | |
| 734 | |
| 735 | |
| 736 | |
| 737 | |
| 738 | |
| 739 | |
| 740 | |
| 741 | template <typename... _Args> |
| 742 | iterator |
| 743 | try_emplace(const_iterator __hint, const key_type& __k, |
| 744 | _Args&&... __args) |
| 745 | { |
| 746 | iterator __i; |
| 747 | auto __true_hint = _M_t._M_get_insert_hint_unique_pos(__hint, __k); |
| 748 | if (__true_hint.second) |
| 749 | __i = emplace_hint(iterator(__true_hint.second), |
| 750 | std::piecewise_construct, |
| 751 | std::forward_as_tuple(__k), |
| 752 | std::forward_as_tuple( |
| 753 | std::forward<_Args>(__args)...)); |
| 754 | else |
| 755 | __i = iterator(__true_hint.first); |
| 756 | return __i; |
| 757 | } |
| 758 | |
| 759 | |
| 760 | template <typename... _Args> |
| 761 | iterator |
| 762 | try_emplace(const_iterator __hint, key_type&& __k, _Args&&... __args) |
| 763 | { |
| 764 | iterator __i; |
| 765 | auto __true_hint = _M_t._M_get_insert_hint_unique_pos(__hint, __k); |
| 766 | if (__true_hint.second) |
| 767 | __i = emplace_hint(iterator(__true_hint.second), |
| 768 | std::piecewise_construct, |
| 769 | std::forward_as_tuple(std::move(__k)), |
| 770 | std::forward_as_tuple( |
| 771 | std::forward<_Args>(__args)...)); |
| 772 | else |
| 773 | __i = iterator(__true_hint.first); |
| 774 | return __i; |
| 775 | } |
| 776 | #endif |
| 777 | |
| 778 | |
| 779 | |
| 780 | |
| 781 | |
| 782 | |
| 783 | |
| 784 | |
| 785 | |
| 786 | |
| 787 | |
| 788 | |
| 789 | |
| 790 | |
| 791 | |
| 792 | |
| 793 | |
| 794 | std::pair<iterator, bool> |
| 795 | insert(const value_type& __x) |
| 796 | { return _M_t._M_insert_unique(__x); } |
| 797 | |
| 798 | #if __cplusplus >= 201103L |
| 799 | |
| 800 | |
| 801 | std::pair<iterator, bool> |
| 802 | insert(value_type&& __x) |
| 803 | { return _M_t._M_insert_unique(std::move(__x)); } |
| 804 | |
| 805 | template<typename _Pair> |
| 806 | __enable_if_t<is_constructible<value_type, _Pair>::value, |
| 807 | pair<iterator, bool>> |
| 808 | insert(_Pair&& __x) |
| 809 | { return _M_t._M_emplace_unique(std::forward<_Pair>(__x)); } |
| 810 | #endif |
| 811 | |
| 812 | |
| 813 | #if __cplusplus >= 201103L |
| 814 | |
| 815 | |
| 816 | |
| 817 | |
| 818 | |
| 819 | |
| 820 | |
| 821 | void |
| 822 | insert(std::initializer_list<value_type> __list) |
| 823 | { insert(__list.begin(), __list.end()); } |
| 824 | #endif |
| 825 | |
| 826 | |
| 827 | |
| 828 | |
| 829 | |
| 830 | |
| 831 | |
| 832 | |
| 833 | |
| 834 | |
| 835 | |
| 836 | |
| 837 | |
| 838 | |
| 839 | |
| 840 | |
| 841 | |
| 842 | |
| 843 | |
| 844 | |
| 845 | |
| 846 | |
| 847 | |
| 848 | |
| 849 | |
| 850 | iterator |
| 851 | #if __cplusplus >= 201103L |
| 852 | insert(const_iterator __position, const value_type& __x) |
| 853 | #else |
| 854 | insert(iterator __position, const value_type& __x) |
| 855 | #endif |
| 856 | { return _M_t._M_insert_unique_(__position, __x); } |
| 857 | |
| 858 | #if __cplusplus >= 201103L |
| 859 | |
| 860 | |
| 861 | iterator |
| 862 | insert(const_iterator __position, value_type&& __x) |
| 863 | { return _M_t._M_insert_unique_(__position, std::move(__x)); } |
| 864 | |
| 865 | template<typename _Pair> |
| 866 | __enable_if_t<is_constructible<value_type, _Pair>::value, iterator> |
| 867 | insert(const_iterator __position, _Pair&& __x) |
| 868 | { |
| 869 | return _M_t._M_emplace_hint_unique(__position, |
| 870 | std::forward<_Pair>(__x)); |
| 871 | } |
| 872 | #endif |
| 873 | |
| 874 | |
| 875 | |
| 876 | |
| 877 | |
| 878 | |
| 879 | |
| 880 | |
| 881 | |
| 882 | |
| 883 | template<typename _InputIterator> |
| 884 | void |
| 885 | insert(_InputIterator __first, _InputIterator __last) |
| 886 | { _M_t._M_insert_unique(__first, __last); } |
| 887 | |
| 888 | #if __cplusplus > 201402L |
| 889 | #define __cpp_lib_map_insertion 201411 |
| 890 | |
| 891 | |
| 892 | |
| 893 | |
| 894 | |
| 895 | |
| 896 | |
| 897 | |
| 898 | |
| 899 | |
| 900 | |
| 901 | |
| 902 | |
| 903 | |
| 904 | |
| 905 | |
| 906 | |
| 907 | |
| 908 | |
| 909 | template <typename _Obj> |
| 910 | pair<iterator, bool> |
| 911 | insert_or_assign(const key_type& __k, _Obj&& __obj) |
| 912 | { |
| 913 | iterator __i = lower_bound(__k); |
| 914 | if (__i == end() || key_comp()(__k, (*__i).first)) |
| 915 | { |
| 916 | __i = emplace_hint(__i, std::piecewise_construct, |
| 917 | std::forward_as_tuple(__k), |
| 918 | std::forward_as_tuple( |
| 919 | std::forward<_Obj>(__obj))); |
| 920 | return {__i, true}; |
| 921 | } |
| 922 | (*__i).second = std::forward<_Obj>(__obj); |
| 923 | return {__i, false}; |
| 924 | } |
| 925 | |
| 926 | |
| 927 | template <typename _Obj> |
| 928 | pair<iterator, bool> |
| 929 | insert_or_assign(key_type&& __k, _Obj&& __obj) |
| 930 | { |
| 931 | iterator __i = lower_bound(__k); |
| 932 | if (__i == end() || key_comp()(__k, (*__i).first)) |
| 933 | { |
| 934 | __i = emplace_hint(__i, std::piecewise_construct, |
| 935 | std::forward_as_tuple(std::move(__k)), |
| 936 | std::forward_as_tuple( |
| 937 | std::forward<_Obj>(__obj))); |
| 938 | return {__i, true}; |
| 939 | } |
| 940 | (*__i).second = std::forward<_Obj>(__obj); |
| 941 | return {__i, false}; |
| 942 | } |
| 943 | |
| 944 | |
| 945 | |
| 946 | |
| 947 | |
| 948 | |
| 949 | |
| 950 | |
| 951 | |
| 952 | |
| 953 | |
| 954 | |
| 955 | |
| 956 | |
| 957 | |
| 958 | |
| 959 | |
| 960 | |
| 961 | |
| 962 | |
| 963 | |
| 964 | template <typename _Obj> |
| 965 | iterator |
| 966 | insert_or_assign(const_iterator __hint, |
| 967 | const key_type& __k, _Obj&& __obj) |
| 968 | { |
| 969 | iterator __i; |
| 970 | auto __true_hint = _M_t._M_get_insert_hint_unique_pos(__hint, __k); |
| 971 | if (__true_hint.second) |
| 972 | { |
| 973 | return emplace_hint(iterator(__true_hint.second), |
| 974 | std::piecewise_construct, |
| 975 | std::forward_as_tuple(__k), |
| 976 | std::forward_as_tuple( |
| 977 | std::forward<_Obj>(__obj))); |
| 978 | } |
| 979 | __i = iterator(__true_hint.first); |
| 980 | (*__i).second = std::forward<_Obj>(__obj); |
| 981 | return __i; |
| 982 | } |
| 983 | |
| 984 | |
| 985 | template <typename _Obj> |
| 986 | iterator |
| 987 | insert_or_assign(const_iterator __hint, key_type&& __k, _Obj&& __obj) |
| 988 | { |
| 989 | iterator __i; |
| 990 | auto __true_hint = _M_t._M_get_insert_hint_unique_pos(__hint, __k); |
| 991 | if (__true_hint.second) |
| 992 | { |
| 993 | return emplace_hint(iterator(__true_hint.second), |
| 994 | std::piecewise_construct, |
| 995 | std::forward_as_tuple(std::move(__k)), |
| 996 | std::forward_as_tuple( |
| 997 | std::forward<_Obj>(__obj))); |
| 998 | } |
| 999 | __i = iterator(__true_hint.first); |
| 1000 | (*__i).second = std::forward<_Obj>(__obj); |
| 1001 | return __i; |
| 1002 | } |
| 1003 | #endif |
| 1004 | |
| 1005 | #if __cplusplus >= 201103L |
| 1006 | |
| 1007 | |
| 1008 | |
| 1009 | |
| 1010 | |
| 1011 | |
| 1012 | |
| 1013 | |
| 1014 | |
| 1015 | |
| 1016 | |
| 1017 | |
| 1018 | |
| 1019 | |
| 1020 | |
| 1021 | |
| 1022 | |
| 1023 | iterator |
| 1024 | erase(const_iterator __position) |
| 1025 | { return _M_t.erase(__position); } |
| 1026 | |
| 1027 | |
| 1028 | _GLIBCXX_ABI_TAG_CXX11 |
| 1029 | iterator |
| 1030 | erase(iterator __position) |
| 1031 | { return _M_t.erase(__position); } |
| 1032 | |
| 1033 | #else |
| 1034 | |
| 1035 | |
| 1036 | |
| 1037 | |
| 1038 | |
| 1039 | |
| 1040 | |
| 1041 | |
| 1042 | |
| 1043 | |
| 1044 | void |
| 1045 | erase(iterator __position) |
| 1046 | { _M_t.erase(__position); } |
| 1047 | #endif |
| 1048 | |
| 1049 | |
| 1050 | |
| 1051 | |
| 1052 | |
| 1053 | |
| 1054 | |
| 1055 | |
| 1056 | |
| 1057 | |
| 1058 | |
| 1059 | |
| 1060 | size_type |
| 1061 | erase(const key_type& __x) |
| 1062 | { return _M_t.erase(__x); } |
| 1063 | |
| 1064 | #if __cplusplus >= 201103L |
| 1065 | |
| 1066 | |
| 1067 | |
| 1068 | |
| 1069 | |
| 1070 | |
| 1071 | |
| 1072 | |
| 1073 | |
| 1074 | |
| 1075 | |
| 1076 | |
| 1077 | |
| 1078 | |
| 1079 | |
| 1080 | iterator |
| 1081 | erase(const_iterator __first, const_iterator __last) |
| 1082 | { return _M_t.erase(__first, __last); } |
| 1083 | #else |
| 1084 | |
| 1085 | |
| 1086 | |
| 1087 | |
| 1088 | |
| 1089 | |
| 1090 | |
| 1091 | |
| 1092 | |
| 1093 | |
| 1094 | |
| 1095 | |
| 1096 | void |
| 1097 | erase(iterator __first, iterator __last) |
| 1098 | { _M_t.erase(__first, __last); } |
| 1099 | #endif |
| 1100 | |
| 1101 | |
| 1102 | |
| 1103 | |
| 1104 | |
| 1105 | |
| 1106 | |
| 1107 | |
| 1108 | |
| 1109 | |
| 1110 | |
| 1111 | |
| 1112 | |
| 1113 | |
| 1114 | void |
| 1115 | swap(map& __x) |
| 1116 | _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value) |
| 1117 | { _M_t.swap(__x._M_t); } |
| 1118 | |
| 1119 | |
| 1120 | |
| 1121 | |
| 1122 | |
| 1123 | |
| 1124 | |
| 1125 | void |
| 1126 | clear() _GLIBCXX_NOEXCEPT |
| 1127 | { _M_t.clear(); } |
| 1128 | |
| 1129 | |
| 1130 | |
| 1131 | |
| 1132 | |
| 1133 | |
| 1134 | key_compare |
| 1135 | key_comp() const |
| 1136 | { return _M_t.key_comp(); } |
| 1137 | |
| 1138 | |
| 1139 | |
| 1140 | |
| 1141 | |
| 1142 | value_compare |
| 1143 | value_comp() const |
| 1144 | { return value_compare(_M_t.key_comp()); } |
| 1145 | |
| 1146 | |
| 1147 | |
| 1148 | |
| 1149 | |
| 1150 | |
| 1151 | |
| 1152 | |
| 1153 | |
| 1154 | |
| 1155 | |
| 1156 | |
| 1157 | |
| 1158 | |
| 1159 | |
| 1160 | |
| 1161 | iterator |
| 1162 | find(const key_type& __x) |
| 1163 | { return _M_t.find(__x); } |
| 1164 | |
| 1165 | #if __cplusplus > 201103L |
| 1166 | template<typename _Kt> |
| 1167 | auto |
| 1168 | find(const _Kt& __x) -> decltype(_M_t._M_find_tr(__x)) |
| 1169 | { return _M_t._M_find_tr(__x); } |
| 1170 | #endif |
| 1171 | |
| 1172 | |
| 1173 | |
| 1174 | |
| 1175 | |
| 1176 | |
| 1177 | |
| 1178 | |
| 1179 | |
| 1180 | |
| 1181 | |
| 1182 | |
| 1183 | |
| 1184 | |
| 1185 | |
| 1186 | const_iterator |
| 1187 | find(const key_type& __x) const |
| 1188 | { return _M_t.find(__x); } |
| 1189 | |
| 1190 | #if __cplusplus > 201103L |
| 1191 | template<typename _Kt> |
| 1192 | auto |
| 1193 | find(const _Kt& __x) const -> decltype(_M_t._M_find_tr(__x)) |
| 1194 | { return _M_t._M_find_tr(__x); } |
| 1195 | #endif |
| 1196 | |
| 1197 | |
| 1198 | |
| 1199 | |
| 1200 | |
| 1201 | |
| 1202 | |
| 1203 | |
| 1204 | |
| 1205 | |
| 1206 | |
| 1207 | size_type |
| 1208 | count(const key_type& __x) const |
| 1209 | { return _M_t.find(__x) == _M_t.end() ? 0 : 1; } |
| 1210 | |
| 1211 | #if __cplusplus > 201103L |
| 1212 | template<typename _Kt> |
| 1213 | auto |
| 1214 | count(const _Kt& __x) const -> decltype(_M_t._M_count_tr(__x)) |
| 1215 | { return _M_t._M_count_tr(__x); } |
| 1216 | #endif |
| 1217 | |
| 1218 | |
| 1219 | |
| 1220 | |
| 1221 | |
| 1222 | |
| 1223 | |
| 1224 | |
| 1225 | |
| 1226 | |
| 1227 | |
| 1228 | |
| 1229 | |
| 1230 | |
| 1231 | iterator |
| 1232 | lower_bound(const key_type& __x) |
| 1233 | { return _M_t.lower_bound(__x); } |
| 1234 | |
| 1235 | #if __cplusplus > 201103L |
| 1236 | template<typename _Kt> |
| 1237 | auto |
| 1238 | lower_bound(const _Kt& __x) |
| 1239 | -> decltype(iterator(_M_t._M_lower_bound_tr(__x))) |
| 1240 | { return iterator(_M_t._M_lower_bound_tr(__x)); } |
| 1241 | #endif |
| 1242 | |
| 1243 | |
| 1244 | |
| 1245 | |
| 1246 | |
| 1247 | |
| 1248 | |
| 1249 | |
| 1250 | |
| 1251 | |
| 1252 | |
| 1253 | |
| 1254 | |
| 1255 | |
| 1256 | const_iterator |
| 1257 | lower_bound(const key_type& __x) const |
| 1258 | { return _M_t.lower_bound(__x); } |
| 1259 | |
| 1260 | #if __cplusplus > 201103L |
| 1261 | template<typename _Kt> |
| 1262 | auto |
| 1263 | lower_bound(const _Kt& __x) const |
| 1264 | -> decltype(const_iterator(_M_t._M_lower_bound_tr(__x))) |
| 1265 | { return const_iterator(_M_t._M_lower_bound_tr(__x)); } |
| 1266 | #endif |
| 1267 | |
| 1268 | |
| 1269 | |
| 1270 | |
| 1271 | |
| 1272 | |
| 1273 | |
| 1274 | |
| 1275 | |
| 1276 | iterator |
| 1277 | upper_bound(const key_type& __x) |
| 1278 | { return _M_t.upper_bound(__x); } |
| 1279 | |
| 1280 | #if __cplusplus > 201103L |
| 1281 | template<typename _Kt> |
| 1282 | auto |
| 1283 | upper_bound(const _Kt& __x) |
| 1284 | -> decltype(iterator(_M_t._M_upper_bound_tr(__x))) |
| 1285 | { return iterator(_M_t._M_upper_bound_tr(__x)); } |
| 1286 | #endif |
| 1287 | |
| 1288 | |
| 1289 | |
| 1290 | |
| 1291 | |
| 1292 | |
| 1293 | |
| 1294 | |
| 1295 | |
| 1296 | const_iterator |
| 1297 | upper_bound(const key_type& __x) const |
| 1298 | { return _M_t.upper_bound(__x); } |
| 1299 | |
| 1300 | #if __cplusplus > 201103L |
| 1301 | template<typename _Kt> |
| 1302 | auto |
| 1303 | upper_bound(const _Kt& __x) const |
| 1304 | -> decltype(const_iterator(_M_t._M_upper_bound_tr(__x))) |
| 1305 | { return const_iterator(_M_t._M_upper_bound_tr(__x)); } |
| 1306 | #endif |
| 1307 | |
| 1308 | |
| 1309 | |
| 1310 | |
| 1311 | |
| 1312 | |
| 1313 | |
| 1314 | |
| 1315 | |
| 1316 | |
| 1317 | |
| 1318 | |
| 1319 | |
| 1320 | |
| 1321 | |
| 1322 | |
| 1323 | |
| 1324 | |
| 1325 | std::pair<iterator, iterator> |
| 1326 | equal_range(const key_type& __x) |
| 1327 | { return _M_t.equal_range(__x); } |
| 1328 | |
| 1329 | #if __cplusplus > 201103L |
| 1330 | template<typename _Kt> |
| 1331 | auto |
| 1332 | equal_range(const _Kt& __x) |
| 1333 | -> decltype(pair<iterator, iterator>(_M_t._M_equal_range_tr(__x))) |
| 1334 | { return pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)); } |
| 1335 | #endif |
| 1336 | |
| 1337 | |
| 1338 | |
| 1339 | |
| 1340 | |
| 1341 | |
| 1342 | |
| 1343 | |
| 1344 | |
| 1345 | |
| 1346 | |
| 1347 | |
| 1348 | |
| 1349 | |
| 1350 | |
| 1351 | |
| 1352 | |
| 1353 | |
| 1354 | std::pair<const_iterator, const_iterator> |
| 1355 | equal_range(const key_type& __x) const |
| 1356 | { return _M_t.equal_range(__x); } |
| 1357 | |
| 1358 | #if __cplusplus > 201103L |
| 1359 | template<typename _Kt> |
| 1360 | auto |
| 1361 | equal_range(const _Kt& __x) const |
| 1362 | -> decltype(pair<const_iterator, const_iterator>( |
| 1363 | _M_t._M_equal_range_tr(__x))) |
| 1364 | { |
| 1365 | return pair<const_iterator, const_iterator>( |
| 1366 | _M_t._M_equal_range_tr(__x)); |
| 1367 | } |
| 1368 | #endif |
| 1369 | |
| 1370 | |
| 1371 | template<typename _K1, typename _T1, typename _C1, typename _A1> |
| 1372 | friend bool |
| 1373 | operator==(const map<_K1, _T1, _C1, _A1>&, |
| 1374 | const map<_K1, _T1, _C1, _A1>&); |
| 1375 | |
| 1376 | template<typename _K1, typename _T1, typename _C1, typename _A1> |
| 1377 | friend bool |
| 1378 | operator<(const map<_K1, _T1, _C1, _A1>&, |
| 1379 | const map<_K1, _T1, _C1, _A1>&); |
| 1380 | }; |
| 1381 | |
| 1382 | |
| 1383 | |
| 1384 | |
| 1385 | |
| 1386 | |
| 1387 | |
| 1388 | |
| 1389 | |
| 1390 | |
| 1391 | |
| 1392 | template<typename _Key, typename _Tp, typename _Compare, typename _Alloc> |
| 1393 | inline bool |
| 1394 | operator==(const map<_Key, _Tp, _Compare, _Alloc>& __x, |
| 1395 | const map<_Key, _Tp, _Compare, _Alloc>& __y) |
| 1396 | { return __x._M_t == __y._M_t; } |
| 1397 | |
| 1398 | |
| 1399 | |
| 1400 | |
| 1401 | |
| 1402 | |
| 1403 | |
| 1404 | |
| 1405 | |
| 1406 | |
| 1407 | |
| 1408 | |
| 1409 | template<typename _Key, typename _Tp, typename _Compare, typename _Alloc> |
| 1410 | inline bool |
| 1411 | operator<(const map<_Key, _Tp, _Compare, _Alloc>& __x, |
| 1412 | const map<_Key, _Tp, _Compare, _Alloc>& __y) |
| 1413 | { return __x._M_t < __y._M_t; } |
| 1414 | |
| 1415 | |
| 1416 | template<typename _Key, typename _Tp, typename _Compare, typename _Alloc> |
| 1417 | inline bool |
| 1418 | operator!=(const map<_Key, _Tp, _Compare, _Alloc>& __x, |
| 1419 | const map<_Key, _Tp, _Compare, _Alloc>& __y) |
| 1420 | { return !(__x == __y); } |
| 1421 | |
| 1422 | |
| 1423 | template<typename _Key, typename _Tp, typename _Compare, typename _Alloc> |
| 1424 | inline bool |
| 1425 | operator>(const map<_Key, _Tp, _Compare, _Alloc>& __x, |
| 1426 | const map<_Key, _Tp, _Compare, _Alloc>& __y) |
| 1427 | { return __y < __x; } |
| 1428 | |
| 1429 | |
| 1430 | template<typename _Key, typename _Tp, typename _Compare, typename _Alloc> |
| 1431 | inline bool |
| 1432 | operator<=(const map<_Key, _Tp, _Compare, _Alloc>& __x, |
| 1433 | const map<_Key, _Tp, _Compare, _Alloc>& __y) |
| 1434 | { return !(__y < __x); } |
| 1435 | |
| 1436 | |
| 1437 | template<typename _Key, typename _Tp, typename _Compare, typename _Alloc> |
| 1438 | inline bool |
| 1439 | operator>=(const map<_Key, _Tp, _Compare, _Alloc>& __x, |
| 1440 | const map<_Key, _Tp, _Compare, _Alloc>& __y) |
| 1441 | { return !(__x < __y); } |
| 1442 | |
| 1443 | |
| 1444 | template<typename _Key, typename _Tp, typename _Compare, typename _Alloc> |
| 1445 | inline void |
| 1446 | swap(map<_Key, _Tp, _Compare, _Alloc>& __x, |
| 1447 | map<_Key, _Tp, _Compare, _Alloc>& __y) |
| 1448 | _GLIBCXX_NOEXCEPT_IF(noexcept(__x.swap(__y))) |
| 1449 | { __x.swap(__y); } |
| 1450 | |
| 1451 | _GLIBCXX_END_NAMESPACE_CONTAINER |
| 1452 | |
| 1453 | #if __cplusplus > 201402L |
| 1454 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
| 1455 | |
| 1456 | template<typename _Key, typename _Val, typename _Cmp1, typename _Alloc, |
| 1457 | typename _Cmp2> |
| 1458 | struct |
| 1459 | _Rb_tree_merge_helper<_GLIBCXX_STD_C::map<_Key, _Val, _Cmp1, _Alloc>, |
| 1460 | _Cmp2> |
| 1461 | { |
| 1462 | private: |
| 1463 | friend class _GLIBCXX_STD_C::map<_Key, _Val, _Cmp1, _Alloc>; |
| 1464 | |
| 1465 | static auto& |
| 1466 | _S_get_tree(_GLIBCXX_STD_C::map<_Key, _Val, _Cmp2, _Alloc>& __map) |
| 1467 | { return __map._M_t; } |
| 1468 | |
| 1469 | static auto& |
| 1470 | _S_get_tree(_GLIBCXX_STD_C::multimap<_Key, _Val, _Cmp2, _Alloc>& __map) |
| 1471 | { return __map._M_t; } |
| 1472 | }; |
| 1473 | _GLIBCXX_END_NAMESPACE_VERSION |
| 1474 | #endif |
| 1475 | |
| 1476 | } |
| 1477 | |
| 1478 | #endif |
| 1479 | |