2 //===----------------------------- map ------------------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
21 template <class Key, class T, class Compare = less<Key>,
22 class Allocator = allocator<pair<const Key, T>>>
28 typedef T mapped_type;
29 typedef pair<const key_type, mapped_type> value_type;
30 typedef Compare key_compare;
31 typedef Allocator allocator_type;
32 typedef typename allocator_type::reference reference;
33 typedef typename allocator_type::const_reference const_reference;
34 typedef typename allocator_type::pointer pointer;
35 typedef typename allocator_type::const_pointer const_pointer;
36 typedef typename allocator_type::size_type size_type;
37 typedef typename allocator_type::difference_type difference_type;
39 typedef implementation-defined iterator;
40 typedef implementation-defined const_iterator;
41 typedef std::reverse_iterator<iterator> reverse_iterator;
42 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
43 typedef unspecified node_type; // C++17
44 typedef INSERT_RETURN_TYPE<iterator, node_type> insert_return_type; // C++17
47 : public binary_function<value_type, value_type, bool>
53 value_compare(key_compare c);
55 bool operator()(const value_type& x, const value_type& y) const;
58 // construct/copy/destroy:
61 is_nothrow_default_constructible<allocator_type>::value &&
62 is_nothrow_default_constructible<key_compare>::value &&
63 is_nothrow_copy_constructible<key_compare>::value);
64 explicit map(const key_compare& comp);
65 map(const key_compare& comp, const allocator_type& a);
66 template <class InputIterator>
67 map(InputIterator first, InputIterator last,
68 const key_compare& comp = key_compare());
69 template <class InputIterator>
70 map(InputIterator first, InputIterator last,
71 const key_compare& comp, const allocator_type& a);
75 is_nothrow_move_constructible<allocator_type>::value &&
76 is_nothrow_move_constructible<key_compare>::value);
77 explicit map(const allocator_type& a);
78 map(const map& m, const allocator_type& a);
79 map(map&& m, const allocator_type& a);
80 map(initializer_list<value_type> il, const key_compare& comp = key_compare());
81 map(initializer_list<value_type> il, const key_compare& comp, const allocator_type& a);
82 template <class InputIterator>
83 map(InputIterator first, InputIterator last, const allocator_type& a)
84 : map(first, last, Compare(), a) {} // C++14
85 map(initializer_list<value_type> il, const allocator_type& a)
86 : map(il, Compare(), a) {} // C++14
89 map& operator=(const map& m);
90 map& operator=(map&& m)
92 allocator_type::propagate_on_container_move_assignment::value &&
93 is_nothrow_move_assignable<allocator_type>::value &&
94 is_nothrow_move_assignable<key_compare>::value);
95 map& operator=(initializer_list<value_type> il);
98 iterator begin() noexcept;
99 const_iterator begin() const noexcept;
100 iterator end() noexcept;
101 const_iterator end() const noexcept;
103 reverse_iterator rbegin() noexcept;
104 const_reverse_iterator rbegin() const noexcept;
105 reverse_iterator rend() noexcept;
106 const_reverse_iterator rend() const noexcept;
108 const_iterator cbegin() const noexcept;
109 const_iterator cend() const noexcept;
110 const_reverse_iterator crbegin() const noexcept;
111 const_reverse_iterator crend() const noexcept;
114 bool empty() const noexcept;
115 size_type size() const noexcept;
116 size_type max_size() const noexcept;
119 mapped_type& operator[](const key_type& k);
120 mapped_type& operator[](key_type&& k);
122 mapped_type& at(const key_type& k);
123 const mapped_type& at(const key_type& k) const;
126 template <class... Args>
127 pair<iterator, bool> emplace(Args&&... args);
128 template <class... Args>
129 iterator emplace_hint(const_iterator position, Args&&... args);
130 pair<iterator, bool> insert(const value_type& v);
131 pair<iterator, bool> insert( value_type&& v); // C++17
133 pair<iterator, bool> insert(P&& p);
134 iterator insert(const_iterator position, const value_type& v);
135 iterator insert(const_iterator position, value_type&& v); // C++17
137 iterator insert(const_iterator position, P&& p);
138 template <class InputIterator>
139 void insert(InputIterator first, InputIterator last);
140 void insert(initializer_list<value_type> il);
142 node_type extract(const_iterator position); // C++17
143 node_type extract(const key_type& x); // C++17
144 insert_return_type insert(node_type&& nh); // C++17
145 iterator insert(const_iterator hint, node_type&& nh); // C++17
147 template <class... Args>
148 pair<iterator, bool> try_emplace(const key_type& k, Args&&... args); // C++17
149 template <class... Args>
150 pair<iterator, bool> try_emplace(key_type&& k, Args&&... args); // C++17
151 template <class... Args>
152 iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args); // C++17
153 template <class... Args>
154 iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args); // C++17
156 pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj); // C++17
158 pair<iterator, bool> insert_or_assign(key_type&& k, M&& obj); // C++17
160 iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj); // C++17
162 iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj); // C++17
164 iterator erase(const_iterator position);
165 iterator erase(iterator position); // C++14
166 size_type erase(const key_type& k);
167 iterator erase(const_iterator first, const_iterator last);
168 void clear() noexcept;
171 void merge(map<Key, T, C2, Allocator>& source); // C++17
173 void merge(map<Key, T, C2, Allocator>&& source); // C++17
175 void merge(multimap<Key, T, C2, Allocator>& source); // C++17
177 void merge(multimap<Key, T, C2, Allocator>&& source); // C++17
180 noexcept(allocator_traits<allocator_type>::is_always_equal::value &&
181 is_nothrow_swappable<key_compare>::value); // C++17
184 allocator_type get_allocator() const noexcept;
185 key_compare key_comp() const;
186 value_compare value_comp() const;
189 iterator find(const key_type& k);
190 const_iterator find(const key_type& k) const;
192 iterator find(const K& x); // C++14
194 const_iterator find(const K& x) const; // C++14
196 size_type count(const K& x) const; // C++14
198 size_type count(const key_type& k) const;
199 iterator lower_bound(const key_type& k);
200 const_iterator lower_bound(const key_type& k) const;
202 iterator lower_bound(const K& x); // C++14
204 const_iterator lower_bound(const K& x) const; // C++14
206 iterator upper_bound(const key_type& k);
207 const_iterator upper_bound(const key_type& k) const;
209 iterator upper_bound(const K& x); // C++14
211 const_iterator upper_bound(const K& x) const; // C++14
213 pair<iterator,iterator> equal_range(const key_type& k);
214 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
216 pair<iterator,iterator> equal_range(const K& x); // C++14
218 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
221 template <class Key, class T, class Compare, class Allocator>
223 operator==(const map<Key, T, Compare, Allocator>& x,
224 const map<Key, T, Compare, Allocator>& y);
226 template <class Key, class T, class Compare, class Allocator>
228 operator< (const map<Key, T, Compare, Allocator>& x,
229 const map<Key, T, Compare, Allocator>& y);
231 template <class Key, class T, class Compare, class Allocator>
233 operator!=(const map<Key, T, Compare, Allocator>& x,
234 const map<Key, T, Compare, Allocator>& y);
236 template <class Key, class T, class Compare, class Allocator>
238 operator> (const map<Key, T, Compare, Allocator>& x,
239 const map<Key, T, Compare, Allocator>& y);
241 template <class Key, class T, class Compare, class Allocator>
243 operator>=(const map<Key, T, Compare, Allocator>& x,
244 const map<Key, T, Compare, Allocator>& y);
246 template <class Key, class T, class Compare, class Allocator>
248 operator<=(const map<Key, T, Compare, Allocator>& x,
249 const map<Key, T, Compare, Allocator>& y);
251 // specialized algorithms:
252 template <class Key, class T, class Compare, class Allocator>
254 swap(map<Key, T, Compare, Allocator>& x, map<Key, T, Compare, Allocator>& y)
255 noexcept(noexcept(x.swap(y)));
257 template <class Key, class T, class Compare, class Allocator, class Predicate>
258 void erase_if(map<Key, T, Compare, Allocator>& c, Predicate pred); // C++20
261 template <class Key, class T, class Compare = less<Key>,
262 class Allocator = allocator<pair<const Key, T>>>
267 typedef Key key_type;
268 typedef T mapped_type;
269 typedef pair<const key_type,mapped_type> value_type;
270 typedef Compare key_compare;
271 typedef Allocator allocator_type;
272 typedef typename allocator_type::reference reference;
273 typedef typename allocator_type::const_reference const_reference;
274 typedef typename allocator_type::size_type size_type;
275 typedef typename allocator_type::difference_type difference_type;
276 typedef typename allocator_type::pointer pointer;
277 typedef typename allocator_type::const_pointer const_pointer;
279 typedef implementation-defined iterator;
280 typedef implementation-defined const_iterator;
281 typedef std::reverse_iterator<iterator> reverse_iterator;
282 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
283 typedef unspecified node_type; // C++17
286 : public binary_function<value_type,value_type,bool>
288 friend class multimap;
291 value_compare(key_compare c);
293 bool operator()(const value_type& x, const value_type& y) const;
296 // construct/copy/destroy:
299 is_nothrow_default_constructible<allocator_type>::value &&
300 is_nothrow_default_constructible<key_compare>::value &&
301 is_nothrow_copy_constructible<key_compare>::value);
302 explicit multimap(const key_compare& comp);
303 multimap(const key_compare& comp, const allocator_type& a);
304 template <class InputIterator>
305 multimap(InputIterator first, InputIterator last, const key_compare& comp);
306 template <class InputIterator>
307 multimap(InputIterator first, InputIterator last, const key_compare& comp,
308 const allocator_type& a);
309 multimap(const multimap& m);
310 multimap(multimap&& m)
312 is_nothrow_move_constructible<allocator_type>::value &&
313 is_nothrow_move_constructible<key_compare>::value);
314 explicit multimap(const allocator_type& a);
315 multimap(const multimap& m, const allocator_type& a);
316 multimap(multimap&& m, const allocator_type& a);
317 multimap(initializer_list<value_type> il, const key_compare& comp = key_compare());
318 multimap(initializer_list<value_type> il, const key_compare& comp,
319 const allocator_type& a);
320 template <class InputIterator>
321 multimap(InputIterator first, InputIterator last, const allocator_type& a)
322 : multimap(first, last, Compare(), a) {} // C++14
323 multimap(initializer_list<value_type> il, const allocator_type& a)
324 : multimap(il, Compare(), a) {} // C++14
327 multimap& operator=(const multimap& m);
328 multimap& operator=(multimap&& m)
330 allocator_type::propagate_on_container_move_assignment::value &&
331 is_nothrow_move_assignable<allocator_type>::value &&
332 is_nothrow_move_assignable<key_compare>::value);
333 multimap& operator=(initializer_list<value_type> il);
336 iterator begin() noexcept;
337 const_iterator begin() const noexcept;
338 iterator end() noexcept;
339 const_iterator end() const noexcept;
341 reverse_iterator rbegin() noexcept;
342 const_reverse_iterator rbegin() const noexcept;
343 reverse_iterator rend() noexcept;
344 const_reverse_iterator rend() const noexcept;
346 const_iterator cbegin() const noexcept;
347 const_iterator cend() const noexcept;
348 const_reverse_iterator crbegin() const noexcept;
349 const_reverse_iterator crend() const noexcept;
352 bool empty() const noexcept;
353 size_type size() const noexcept;
354 size_type max_size() const noexcept;
357 template <class... Args>
358 iterator emplace(Args&&... args);
359 template <class... Args>
360 iterator emplace_hint(const_iterator position, Args&&... args);
361 iterator insert(const value_type& v);
362 iterator insert( value_type&& v); // C++17
364 iterator insert(P&& p);
365 iterator insert(const_iterator position, const value_type& v);
366 iterator insert(const_iterator position, value_type&& v); // C++17
368 iterator insert(const_iterator position, P&& p);
369 template <class InputIterator>
370 void insert(InputIterator first, InputIterator last);
371 void insert(initializer_list<value_type> il);
373 node_type extract(const_iterator position); // C++17
374 node_type extract(const key_type& x); // C++17
375 iterator insert(node_type&& nh); // C++17
376 iterator insert(const_iterator hint, node_type&& nh); // C++17
378 iterator erase(const_iterator position);
379 iterator erase(iterator position); // C++14
380 size_type erase(const key_type& k);
381 iterator erase(const_iterator first, const_iterator last);
382 void clear() noexcept;
385 void merge(multimap<Key, T, C2, Allocator>& source); // C++17
387 void merge(multimap<Key, T, C2, Allocator>&& source); // C++17
389 void merge(map<Key, T, C2, Allocator>& source); // C++17
391 void merge(map<Key, T, C2, Allocator>&& source); // C++17
393 void swap(multimap& m)
394 noexcept(allocator_traits<allocator_type>::is_always_equal::value &&
395 is_nothrow_swappable<key_compare>::value); // C++17
398 allocator_type get_allocator() const noexcept;
399 key_compare key_comp() const;
400 value_compare value_comp() const;
403 iterator find(const key_type& k);
404 const_iterator find(const key_type& k) const;
406 iterator find(const K& x); // C++14
408 const_iterator find(const K& x) const; // C++14
410 size_type count(const K& x) const; // C++14
412 size_type count(const key_type& k) const;
413 iterator lower_bound(const key_type& k);
414 const_iterator lower_bound(const key_type& k) const;
416 iterator lower_bound(const K& x); // C++14
418 const_iterator lower_bound(const K& x) const; // C++14
420 iterator upper_bound(const key_type& k);
421 const_iterator upper_bound(const key_type& k) const;
423 iterator upper_bound(const K& x); // C++14
425 const_iterator upper_bound(const K& x) const; // C++14
427 pair<iterator,iterator> equal_range(const key_type& k);
428 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
430 pair<iterator,iterator> equal_range(const K& x); // C++14
432 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
435 template <class Key, class T, class Compare, class Allocator>
437 operator==(const multimap<Key, T, Compare, Allocator>& x,
438 const multimap<Key, T, Compare, Allocator>& y);
440 template <class Key, class T, class Compare, class Allocator>
442 operator< (const multimap<Key, T, Compare, Allocator>& x,
443 const multimap<Key, T, Compare, Allocator>& y);
445 template <class Key, class T, class Compare, class Allocator>
447 operator!=(const multimap<Key, T, Compare, Allocator>& x,
448 const multimap<Key, T, Compare, Allocator>& y);
450 template <class Key, class T, class Compare, class Allocator>
452 operator> (const multimap<Key, T, Compare, Allocator>& x,
453 const multimap<Key, T, Compare, Allocator>& y);
455 template <class Key, class T, class Compare, class Allocator>
457 operator>=(const multimap<Key, T, Compare, Allocator>& x,
458 const multimap<Key, T, Compare, Allocator>& y);
460 template <class Key, class T, class Compare, class Allocator>
462 operator<=(const multimap<Key, T, Compare, Allocator>& x,
463 const multimap<Key, T, Compare, Allocator>& y);
465 // specialized algorithms:
466 template <class Key, class T, class Compare, class Allocator>
468 swap(multimap<Key, T, Compare, Allocator>& x,
469 multimap<Key, T, Compare, Allocator>& y)
470 noexcept(noexcept(x.swap(y)));
472 template <class Key, class T, class Compare, class Allocator, class Predicate>
473 void erase_if(multimap<Key, T, Compare, Allocator>& c, Predicate pred); // C++20
481 #include <__node_handle>
485 #include <functional>
486 #include <initializer_list>
487 #include <type_traits>
490 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
491 #pragma GCC system_header
494 _LIBCPP_BEGIN_NAMESPACE_STD
496 template <class _Key, class _CP, class _Compare,
497 bool = is_empty<_Compare>::value && !__libcpp_is_final<_Compare>::value>
498 class __map_value_compare
502 _LIBCPP_INLINE_VISIBILITY
503 __map_value_compare()
504 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
506 _LIBCPP_INLINE_VISIBILITY
507 __map_value_compare(_Compare c)
508 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
510 _LIBCPP_INLINE_VISIBILITY
511 const _Compare& key_comp() const _NOEXCEPT {return *this;}
512 _LIBCPP_INLINE_VISIBILITY
513 bool operator()(const _CP& __x, const _CP& __y) const
514 {return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y.__get_value().first);}
515 _LIBCPP_INLINE_VISIBILITY
516 bool operator()(const _CP& __x, const _Key& __y) const
517 {return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y);}
518 _LIBCPP_INLINE_VISIBILITY
519 bool operator()(const _Key& __x, const _CP& __y) const
520 {return static_cast<const _Compare&>(*this)(__x, __y.__get_value().first);}
521 void swap(__map_value_compare&__y)
522 _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value)
525 swap(static_cast<_Compare&>(*this), static_cast<_Compare&>(__y));
528 #if _LIBCPP_STD_VER > 11
529 template <typename _K2>
530 _LIBCPP_INLINE_VISIBILITY
531 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
532 operator () ( const _K2& __x, const _CP& __y ) const
533 {return static_cast<const _Compare&>(*this) (__x, __y.__get_value().first);}
535 template <typename _K2>
536 _LIBCPP_INLINE_VISIBILITY
537 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
538 operator () (const _CP& __x, const _K2& __y) const
539 {return static_cast<const _Compare&>(*this) (__x.__get_value().first, __y);}
543 template <class _Key, class _CP, class _Compare>
544 class __map_value_compare<_Key, _CP, _Compare, false>
549 _LIBCPP_INLINE_VISIBILITY
550 __map_value_compare()
551 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
553 _LIBCPP_INLINE_VISIBILITY
554 __map_value_compare(_Compare c)
555 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
557 _LIBCPP_INLINE_VISIBILITY
558 const _Compare& key_comp() const _NOEXCEPT {return comp;}
560 _LIBCPP_INLINE_VISIBILITY
561 bool operator()(const _CP& __x, const _CP& __y) const
562 {return comp(__x.__get_value().first, __y.__get_value().first);}
563 _LIBCPP_INLINE_VISIBILITY
564 bool operator()(const _CP& __x, const _Key& __y) const
565 {return comp(__x.__get_value().first, __y);}
566 _LIBCPP_INLINE_VISIBILITY
567 bool operator()(const _Key& __x, const _CP& __y) const
568 {return comp(__x, __y.__get_value().first);}
569 void swap(__map_value_compare&__y)
570 _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value)
573 swap(comp, __y.comp);
576 #if _LIBCPP_STD_VER > 11
577 template <typename _K2>
578 _LIBCPP_INLINE_VISIBILITY
579 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
580 operator () ( const _K2& __x, const _CP& __y ) const
581 {return comp (__x, __y.__get_value().first);}
583 template <typename _K2>
584 _LIBCPP_INLINE_VISIBILITY
585 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
586 operator () (const _CP& __x, const _K2& __y) const
587 {return comp (__x.__get_value().first, __y);}
591 template <class _Key, class _CP, class _Compare, bool __b>
592 inline _LIBCPP_INLINE_VISIBILITY
594 swap(__map_value_compare<_Key, _CP, _Compare, __b>& __x,
595 __map_value_compare<_Key, _CP, _Compare, __b>& __y)
596 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
601 template <class _Allocator>
602 class __map_node_destructor
604 typedef _Allocator allocator_type;
605 typedef allocator_traits<allocator_type> __alloc_traits;
608 typedef typename __alloc_traits::pointer pointer;
611 allocator_type& __na_;
613 __map_node_destructor& operator=(const __map_node_destructor&);
616 bool __first_constructed;
617 bool __second_constructed;
619 _LIBCPP_INLINE_VISIBILITY
620 explicit __map_node_destructor(allocator_type& __na) _NOEXCEPT
622 __first_constructed(false),
623 __second_constructed(false)
626 #ifndef _LIBCPP_CXX03_LANG
627 _LIBCPP_INLINE_VISIBILITY
628 __map_node_destructor(__tree_node_destructor<allocator_type>&& __x) _NOEXCEPT
630 __first_constructed(__x.__value_constructed),
631 __second_constructed(__x.__value_constructed)
633 __x.__value_constructed = false;
635 #endif // _LIBCPP_CXX03_LANG
637 _LIBCPP_INLINE_VISIBILITY
638 void operator()(pointer __p) _NOEXCEPT
640 if (__second_constructed)
641 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__get_value().second));
642 if (__first_constructed)
643 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__get_value().first));
645 __alloc_traits::deallocate(__na_, __p, 1);
649 template <class _Key, class _Tp, class _Compare, class _Allocator>
651 template <class _Key, class _Tp, class _Compare, class _Allocator>
653 template <class _TreeIterator> class __map_const_iterator;
655 #ifndef _LIBCPP_CXX03_LANG
657 template <class _Key, class _Tp>
660 typedef _Key key_type;
661 typedef _Tp mapped_type;
662 typedef pair<const key_type, mapped_type> value_type;
663 typedef pair<key_type&, mapped_type&> __nc_ref_pair_type;
664 typedef pair<key_type&&, mapped_type&&> __nc_rref_pair_type;
670 _LIBCPP_INLINE_VISIBILITY
671 value_type& __get_value()
673 #if _LIBCPP_STD_VER > 14
674 return *_VSTD::launder(_VSTD::addressof(__cc));
680 _LIBCPP_INLINE_VISIBILITY
681 const value_type& __get_value() const
683 #if _LIBCPP_STD_VER > 14
684 return *_VSTD::launder(_VSTD::addressof(__cc));
690 _LIBCPP_INLINE_VISIBILITY
691 __nc_ref_pair_type __ref()
693 value_type& __v = __get_value();
694 return __nc_ref_pair_type(const_cast<key_type&>(__v.first), __v.second);
697 _LIBCPP_INLINE_VISIBILITY
698 __nc_rref_pair_type __move()
700 value_type& __v = __get_value();
701 return __nc_rref_pair_type(
702 _VSTD::move(const_cast<key_type&>(__v.first)),
703 _VSTD::move(__v.second));
706 _LIBCPP_INLINE_VISIBILITY
707 __value_type& operator=(const __value_type& __v)
709 __ref() = __v.__get_value();
713 _LIBCPP_INLINE_VISIBILITY
714 __value_type& operator=(__value_type&& __v)
716 __ref() = __v.__move();
720 template <class _ValueTp,
721 class = typename enable_if<
722 __is_same_uncvref<_ValueTp, value_type>::value
725 _LIBCPP_INLINE_VISIBILITY
726 __value_type& operator=(_ValueTp&& __v)
728 __ref() = _VSTD::forward<_ValueTp>(__v);
733 __value_type() _LIBCPP_EQUAL_DELETE;
734 ~__value_type() _LIBCPP_EQUAL_DELETE;
735 __value_type(const __value_type& __v) _LIBCPP_EQUAL_DELETE;
736 __value_type(__value_type&& __v) _LIBCPP_EQUAL_DELETE;
741 template <class _Key, class _Tp>
744 typedef _Key key_type;
745 typedef _Tp mapped_type;
746 typedef pair<const key_type, mapped_type> value_type;
752 _LIBCPP_INLINE_VISIBILITY
753 value_type& __get_value() { return __cc; }
754 _LIBCPP_INLINE_VISIBILITY
755 const value_type& __get_value() const { return __cc; }
759 __value_type(__value_type const&);
760 __value_type& operator=(__value_type const&);
764 #endif // _LIBCPP_CXX03_LANG
767 struct __extract_key_value_types;
769 template <class _Key, class _Tp>
770 struct __extract_key_value_types<__value_type<_Key, _Tp> >
772 typedef _Key const __key_type;
773 typedef _Tp __mapped_type;
776 template <class _TreeIterator>
777 class _LIBCPP_TEMPLATE_VIS __map_iterator
779 typedef typename _TreeIterator::_NodeTypes _NodeTypes;
780 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
785 typedef bidirectional_iterator_tag iterator_category;
786 typedef typename _NodeTypes::__map_value_type value_type;
787 typedef typename _TreeIterator::difference_type difference_type;
788 typedef value_type& reference;
789 typedef typename _NodeTypes::__map_value_type_pointer pointer;
791 _LIBCPP_INLINE_VISIBILITY
792 __map_iterator() _NOEXCEPT {}
794 _LIBCPP_INLINE_VISIBILITY
795 __map_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
797 _LIBCPP_INLINE_VISIBILITY
798 reference operator*() const {return __i_->__get_value();}
799 _LIBCPP_INLINE_VISIBILITY
800 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());}
802 _LIBCPP_INLINE_VISIBILITY
803 __map_iterator& operator++() {++__i_; return *this;}
804 _LIBCPP_INLINE_VISIBILITY
805 __map_iterator operator++(int)
807 __map_iterator __t(*this);
812 _LIBCPP_INLINE_VISIBILITY
813 __map_iterator& operator--() {--__i_; return *this;}
814 _LIBCPP_INLINE_VISIBILITY
815 __map_iterator operator--(int)
817 __map_iterator __t(*this);
822 friend _LIBCPP_INLINE_VISIBILITY
823 bool operator==(const __map_iterator& __x, const __map_iterator& __y)
824 {return __x.__i_ == __y.__i_;}
826 _LIBCPP_INLINE_VISIBILITY
827 bool operator!=(const __map_iterator& __x, const __map_iterator& __y)
828 {return __x.__i_ != __y.__i_;}
830 template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS map;
831 template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS multimap;
832 template <class> friend class _LIBCPP_TEMPLATE_VIS __map_const_iterator;
835 template <class _TreeIterator>
836 class _LIBCPP_TEMPLATE_VIS __map_const_iterator
838 typedef typename _TreeIterator::_NodeTypes _NodeTypes;
839 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
844 typedef bidirectional_iterator_tag iterator_category;
845 typedef typename _NodeTypes::__map_value_type value_type;
846 typedef typename _TreeIterator::difference_type difference_type;
847 typedef const value_type& reference;
848 typedef typename _NodeTypes::__const_map_value_type_pointer pointer;
850 _LIBCPP_INLINE_VISIBILITY
851 __map_const_iterator() _NOEXCEPT {}
853 _LIBCPP_INLINE_VISIBILITY
854 __map_const_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
855 _LIBCPP_INLINE_VISIBILITY
856 __map_const_iterator(__map_iterator<
857 typename _TreeIterator::__non_const_iterator> __i) _NOEXCEPT
860 _LIBCPP_INLINE_VISIBILITY
861 reference operator*() const {return __i_->__get_value();}
862 _LIBCPP_INLINE_VISIBILITY
863 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());}
865 _LIBCPP_INLINE_VISIBILITY
866 __map_const_iterator& operator++() {++__i_; return *this;}
867 _LIBCPP_INLINE_VISIBILITY
868 __map_const_iterator operator++(int)
870 __map_const_iterator __t(*this);
875 _LIBCPP_INLINE_VISIBILITY
876 __map_const_iterator& operator--() {--__i_; return *this;}
877 _LIBCPP_INLINE_VISIBILITY
878 __map_const_iterator operator--(int)
880 __map_const_iterator __t(*this);
885 friend _LIBCPP_INLINE_VISIBILITY
886 bool operator==(const __map_const_iterator& __x, const __map_const_iterator& __y)
887 {return __x.__i_ == __y.__i_;}
888 friend _LIBCPP_INLINE_VISIBILITY
889 bool operator!=(const __map_const_iterator& __x, const __map_const_iterator& __y)
890 {return __x.__i_ != __y.__i_;}
892 template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS map;
893 template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS multimap;
894 template <class, class, class> friend class _LIBCPP_TEMPLATE_VIS __tree_const_iterator;
897 template <class _Key, class _Tp, class _Compare = less<_Key>,
898 class _Allocator = allocator<pair<const _Key, _Tp> > >
899 class _LIBCPP_TEMPLATE_VIS map
903 typedef _Key key_type;
904 typedef _Tp mapped_type;
905 typedef pair<const key_type, mapped_type> value_type;
906 typedef _Compare key_compare;
907 typedef _Allocator allocator_type;
908 typedef value_type& reference;
909 typedef const value_type& const_reference;
911 static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
912 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
913 "Allocator::value_type must be same type as value_type");
915 class _LIBCPP_TEMPLATE_VIS value_compare
916 : public binary_function<value_type, value_type, bool>
922 _LIBCPP_INLINE_VISIBILITY value_compare(key_compare c) : comp(c) {}
924 _LIBCPP_INLINE_VISIBILITY
925 bool operator()(const value_type& __x, const value_type& __y) const
926 {return comp(__x.first, __y.first);}
931 typedef _VSTD::__value_type<key_type, mapped_type> __value_type;
932 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
933 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
934 __value_type>::type __allocator_type;
935 typedef __tree<__value_type, __vc, __allocator_type> __base;
936 typedef typename __base::__node_traits __node_traits;
937 typedef allocator_traits<allocator_type> __alloc_traits;
942 typedef typename __alloc_traits::pointer pointer;
943 typedef typename __alloc_traits::const_pointer const_pointer;
944 typedef typename __alloc_traits::size_type size_type;
945 typedef typename __alloc_traits::difference_type difference_type;
946 typedef __map_iterator<typename __base::iterator> iterator;
947 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
948 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
949 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
951 #if _LIBCPP_STD_VER > 14
952 typedef __map_node_handle<typename __base::__node, allocator_type> node_type;
953 typedef __insert_return_type<iterator, node_type> insert_return_type;
956 template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
957 friend class _LIBCPP_TEMPLATE_VIS map;
958 template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
959 friend class _LIBCPP_TEMPLATE_VIS multimap;
961 _LIBCPP_INLINE_VISIBILITY
964 is_nothrow_default_constructible<allocator_type>::value &&
965 is_nothrow_default_constructible<key_compare>::value &&
966 is_nothrow_copy_constructible<key_compare>::value)
967 : __tree_(__vc(key_compare())) {}
969 _LIBCPP_INLINE_VISIBILITY
970 explicit map(const key_compare& __comp)
972 is_nothrow_default_constructible<allocator_type>::value &&
973 is_nothrow_copy_constructible<key_compare>::value)
974 : __tree_(__vc(__comp)) {}
976 _LIBCPP_INLINE_VISIBILITY
977 explicit map(const key_compare& __comp, const allocator_type& __a)
978 : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {}
980 template <class _InputIterator>
981 _LIBCPP_INLINE_VISIBILITY
982 map(_InputIterator __f, _InputIterator __l,
983 const key_compare& __comp = key_compare())
984 : __tree_(__vc(__comp))
989 template <class _InputIterator>
990 _LIBCPP_INLINE_VISIBILITY
991 map(_InputIterator __f, _InputIterator __l,
992 const key_compare& __comp, const allocator_type& __a)
993 : __tree_(__vc(__comp), typename __base::allocator_type(__a))
998 #if _LIBCPP_STD_VER > 11
999 template <class _InputIterator>
1000 _LIBCPP_INLINE_VISIBILITY
1001 map(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
1002 : map(__f, __l, key_compare(), __a) {}
1005 _LIBCPP_INLINE_VISIBILITY
1007 : __tree_(__m.__tree_)
1009 insert(__m.begin(), __m.end());
1012 _LIBCPP_INLINE_VISIBILITY
1013 map& operator=(const map& __m)
1015 #ifndef _LIBCPP_CXX03_LANG
1016 __tree_ = __m.__tree_;
1020 __tree_.value_comp() = __m.__tree_.value_comp();
1021 __tree_.__copy_assign_alloc(__m.__tree_);
1022 insert(__m.begin(), __m.end());
1028 #ifndef _LIBCPP_CXX03_LANG
1030 _LIBCPP_INLINE_VISIBILITY
1032 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
1033 : __tree_(_VSTD::move(__m.__tree_))
1037 map(map&& __m, const allocator_type& __a);
1039 _LIBCPP_INLINE_VISIBILITY
1040 map& operator=(map&& __m)
1041 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
1043 __tree_ = _VSTD::move(__m.__tree_);
1047 _LIBCPP_INLINE_VISIBILITY
1048 map(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
1049 : __tree_(__vc(__comp))
1051 insert(__il.begin(), __il.end());
1054 _LIBCPP_INLINE_VISIBILITY
1055 map(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
1056 : __tree_(__vc(__comp), typename __base::allocator_type(__a))
1058 insert(__il.begin(), __il.end());
1061 #if _LIBCPP_STD_VER > 11
1062 _LIBCPP_INLINE_VISIBILITY
1063 map(initializer_list<value_type> __il, const allocator_type& __a)
1064 : map(__il, key_compare(), __a) {}
1067 _LIBCPP_INLINE_VISIBILITY
1068 map& operator=(initializer_list<value_type> __il)
1070 __tree_.__assign_unique(__il.begin(), __il.end());
1074 #endif // _LIBCPP_CXX03_LANG
1076 _LIBCPP_INLINE_VISIBILITY
1077 explicit map(const allocator_type& __a)
1078 : __tree_(typename __base::allocator_type(__a))
1082 _LIBCPP_INLINE_VISIBILITY
1083 map(const map& __m, const allocator_type& __a)
1084 : __tree_(__m.__tree_.value_comp(), typename __base::allocator_type(__a))
1086 insert(__m.begin(), __m.end());
1089 _LIBCPP_INLINE_VISIBILITY
1090 iterator begin() _NOEXCEPT {return __tree_.begin();}
1091 _LIBCPP_INLINE_VISIBILITY
1092 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
1093 _LIBCPP_INLINE_VISIBILITY
1094 iterator end() _NOEXCEPT {return __tree_.end();}
1095 _LIBCPP_INLINE_VISIBILITY
1096 const_iterator end() const _NOEXCEPT {return __tree_.end();}
1098 _LIBCPP_INLINE_VISIBILITY
1099 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
1100 _LIBCPP_INLINE_VISIBILITY
1101 const_reverse_iterator rbegin() const _NOEXCEPT
1102 {return const_reverse_iterator(end());}
1103 _LIBCPP_INLINE_VISIBILITY
1104 reverse_iterator rend() _NOEXCEPT
1105 {return reverse_iterator(begin());}
1106 _LIBCPP_INLINE_VISIBILITY
1107 const_reverse_iterator rend() const _NOEXCEPT
1108 {return const_reverse_iterator(begin());}
1110 _LIBCPP_INLINE_VISIBILITY
1111 const_iterator cbegin() const _NOEXCEPT {return begin();}
1112 _LIBCPP_INLINE_VISIBILITY
1113 const_iterator cend() const _NOEXCEPT {return end();}
1114 _LIBCPP_INLINE_VISIBILITY
1115 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
1116 _LIBCPP_INLINE_VISIBILITY
1117 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
1119 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1120 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
1121 _LIBCPP_INLINE_VISIBILITY
1122 size_type size() const _NOEXCEPT {return __tree_.size();}
1123 _LIBCPP_INLINE_VISIBILITY
1124 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
1126 mapped_type& operator[](const key_type& __k);
1127 #ifndef _LIBCPP_CXX03_LANG
1128 mapped_type& operator[](key_type&& __k);
1131 mapped_type& at(const key_type& __k);
1132 const mapped_type& at(const key_type& __k) const;
1134 _LIBCPP_INLINE_VISIBILITY
1135 allocator_type get_allocator() const _NOEXCEPT {return allocator_type(__tree_.__alloc());}
1136 _LIBCPP_INLINE_VISIBILITY
1137 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
1138 _LIBCPP_INLINE_VISIBILITY
1139 value_compare value_comp() const {return value_compare(__tree_.value_comp().key_comp());}
1141 #ifndef _LIBCPP_CXX03_LANG
1142 template <class ..._Args>
1143 _LIBCPP_INLINE_VISIBILITY
1144 pair<iterator, bool> emplace(_Args&& ...__args) {
1145 return __tree_.__emplace_unique(_VSTD::forward<_Args>(__args)...);
1148 template <class ..._Args>
1149 _LIBCPP_INLINE_VISIBILITY
1150 iterator emplace_hint(const_iterator __p, _Args&& ...__args) {
1151 return __tree_.__emplace_hint_unique(__p.__i_, _VSTD::forward<_Args>(__args)...);
1154 template <class _Pp,
1155 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
1156 _LIBCPP_INLINE_VISIBILITY
1157 pair<iterator, bool> insert(_Pp&& __p)
1158 {return __tree_.__insert_unique(_VSTD::forward<_Pp>(__p));}
1160 template <class _Pp,
1161 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
1162 _LIBCPP_INLINE_VISIBILITY
1163 iterator insert(const_iterator __pos, _Pp&& __p)
1164 {return __tree_.__insert_unique(__pos.__i_, _VSTD::forward<_Pp>(__p));}
1166 #endif // _LIBCPP_CXX03_LANG
1168 _LIBCPP_INLINE_VISIBILITY
1169 pair<iterator, bool>
1170 insert(const value_type& __v) {return __tree_.__insert_unique(__v);}
1172 _LIBCPP_INLINE_VISIBILITY
1174 insert(const_iterator __p, const value_type& __v)
1175 {return __tree_.__insert_unique(__p.__i_, __v);}
1177 #ifndef _LIBCPP_CXX03_LANG
1178 _LIBCPP_INLINE_VISIBILITY
1179 pair<iterator, bool>
1180 insert(value_type&& __v) {return __tree_.__insert_unique(_VSTD::move(__v));}
1182 _LIBCPP_INLINE_VISIBILITY
1183 iterator insert(const_iterator __p, value_type&& __v)
1184 {return __tree_.__insert_unique(__p.__i_, _VSTD::move(__v));}
1186 _LIBCPP_INLINE_VISIBILITY
1187 void insert(initializer_list<value_type> __il)
1188 {insert(__il.begin(), __il.end());}
1191 template <class _InputIterator>
1192 _LIBCPP_INLINE_VISIBILITY
1193 void insert(_InputIterator __f, _InputIterator __l)
1195 for (const_iterator __e = cend(); __f != __l; ++__f)
1196 insert(__e.__i_, *__f);
1199 #if _LIBCPP_STD_VER > 14
1201 template <class... _Args>
1202 _LIBCPP_INLINE_VISIBILITY
1203 pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args)
1205 return __tree_.__emplace_unique_key_args(__k,
1206 _VSTD::piecewise_construct,
1207 _VSTD::forward_as_tuple(__k),
1208 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
1211 template <class... _Args>
1212 _LIBCPP_INLINE_VISIBILITY
1213 pair<iterator, bool> try_emplace(key_type&& __k, _Args&&... __args)
1215 return __tree_.__emplace_unique_key_args(__k,
1216 _VSTD::piecewise_construct,
1217 _VSTD::forward_as_tuple(_VSTD::move(__k)),
1218 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
1221 template <class... _Args>
1222 _LIBCPP_INLINE_VISIBILITY
1223 iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args)
1225 return __tree_.__emplace_hint_unique_key_args(__h.__i_, __k,
1226 _VSTD::piecewise_construct,
1227 _VSTD::forward_as_tuple(__k),
1228 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
1231 template <class... _Args>
1232 _LIBCPP_INLINE_VISIBILITY
1233 iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args)
1235 return __tree_.__emplace_hint_unique_key_args(__h.__i_, __k,
1236 _VSTD::piecewise_construct,
1237 _VSTD::forward_as_tuple(_VSTD::move(__k)),
1238 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
1241 template <class _Vp>
1242 _LIBCPP_INLINE_VISIBILITY
1243 pair<iterator, bool> insert_or_assign(const key_type& __k, _Vp&& __v)
1245 iterator __p = lower_bound(__k);
1246 if ( __p != end() && !key_comp()(__k, __p->first))
1248 __p->second = _VSTD::forward<_Vp>(__v);
1249 return _VSTD::make_pair(__p, false);
1251 return _VSTD::make_pair(emplace_hint(__p, __k, _VSTD::forward<_Vp>(__v)), true);
1254 template <class _Vp>
1255 _LIBCPP_INLINE_VISIBILITY
1256 pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v)
1258 iterator __p = lower_bound(__k);
1259 if ( __p != end() && !key_comp()(__k, __p->first))
1261 __p->second = _VSTD::forward<_Vp>(__v);
1262 return _VSTD::make_pair(__p, false);
1264 return _VSTD::make_pair(emplace_hint(__p, _VSTD::move(__k), _VSTD::forward<_Vp>(__v)), true);
1267 template <class _Vp>
1268 _LIBCPP_INLINE_VISIBILITY
1269 iterator insert_or_assign(const_iterator __h, const key_type& __k, _Vp&& __v)
1271 iterator __p = lower_bound(__k);
1272 if ( __p != end() && !key_comp()(__k, __p->first))
1274 __p->second = _VSTD::forward<_Vp>(__v);
1277 return emplace_hint(__h, __k, _VSTD::forward<_Vp>(__v));
1280 template <class _Vp>
1281 _LIBCPP_INLINE_VISIBILITY
1282 iterator insert_or_assign(const_iterator __h, key_type&& __k, _Vp&& __v)
1284 iterator __p = lower_bound(__k);
1285 if ( __p != end() && !key_comp()(__k, __p->first))
1287 __p->second = _VSTD::forward<_Vp>(__v);
1290 return emplace_hint(__h, _VSTD::move(__k), _VSTD::forward<_Vp>(__v));
1293 #endif // _LIBCPP_STD_VER > 14
1295 _LIBCPP_INLINE_VISIBILITY
1296 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
1297 _LIBCPP_INLINE_VISIBILITY
1298 iterator erase(iterator __p) {return __tree_.erase(__p.__i_);}
1299 _LIBCPP_INLINE_VISIBILITY
1300 size_type erase(const key_type& __k)
1301 {return __tree_.__erase_unique(__k);}
1302 _LIBCPP_INLINE_VISIBILITY
1303 iterator erase(const_iterator __f, const_iterator __l)
1304 {return __tree_.erase(__f.__i_, __l.__i_);}
1305 _LIBCPP_INLINE_VISIBILITY
1306 void clear() _NOEXCEPT {__tree_.clear();}
1308 #if _LIBCPP_STD_VER > 14
1309 _LIBCPP_INLINE_VISIBILITY
1310 insert_return_type insert(node_type&& __nh)
1312 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1313 "node_type with incompatible allocator passed to map::insert()");
1314 return __tree_.template __node_handle_insert_unique<
1315 node_type, insert_return_type>(_VSTD::move(__nh));
1317 _LIBCPP_INLINE_VISIBILITY
1318 iterator insert(const_iterator __hint, node_type&& __nh)
1320 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1321 "node_type with incompatible allocator passed to map::insert()");
1322 return __tree_.template __node_handle_insert_unique<node_type>(
1323 __hint.__i_, _VSTD::move(__nh));
1325 _LIBCPP_INLINE_VISIBILITY
1326 node_type extract(key_type const& __key)
1328 return __tree_.template __node_handle_extract<node_type>(__key);
1330 _LIBCPP_INLINE_VISIBILITY
1331 node_type extract(const_iterator __it)
1333 return __tree_.template __node_handle_extract<node_type>(__it.__i_);
1335 template <class _Compare2>
1336 _LIBCPP_INLINE_VISIBILITY
1337 void merge(map<key_type, mapped_type, _Compare2, allocator_type>& __source)
1339 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1340 "merging container with incompatible allocator");
1341 __tree_.__node_handle_merge_unique(__source.__tree_);
1343 template <class _Compare2>
1344 _LIBCPP_INLINE_VISIBILITY
1345 void merge(map<key_type, mapped_type, _Compare2, allocator_type>&& __source)
1347 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1348 "merging container with incompatible allocator");
1349 __tree_.__node_handle_merge_unique(__source.__tree_);
1351 template <class _Compare2>
1352 _LIBCPP_INLINE_VISIBILITY
1353 void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>& __source)
1355 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1356 "merging container with incompatible allocator");
1357 __tree_.__node_handle_merge_unique(__source.__tree_);
1359 template <class _Compare2>
1360 _LIBCPP_INLINE_VISIBILITY
1361 void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>&& __source)
1363 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1364 "merging container with incompatible allocator");
1365 __tree_.__node_handle_merge_unique(__source.__tree_);
1369 _LIBCPP_INLINE_VISIBILITY
1371 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1372 {__tree_.swap(__m.__tree_);}
1374 _LIBCPP_INLINE_VISIBILITY
1375 iterator find(const key_type& __k) {return __tree_.find(__k);}
1376 _LIBCPP_INLINE_VISIBILITY
1377 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
1378 #if _LIBCPP_STD_VER > 11
1379 template <typename _K2>
1380 _LIBCPP_INLINE_VISIBILITY
1381 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1382 find(const _K2& __k) {return __tree_.find(__k);}
1383 template <typename _K2>
1384 _LIBCPP_INLINE_VISIBILITY
1385 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1386 find(const _K2& __k) const {return __tree_.find(__k);}
1389 _LIBCPP_INLINE_VISIBILITY
1390 size_type count(const key_type& __k) const
1391 {return __tree_.__count_unique(__k);}
1392 #if _LIBCPP_STD_VER > 11
1393 template <typename _K2>
1394 _LIBCPP_INLINE_VISIBILITY
1395 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
1396 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
1398 _LIBCPP_INLINE_VISIBILITY
1399 iterator lower_bound(const key_type& __k)
1400 {return __tree_.lower_bound(__k);}
1401 _LIBCPP_INLINE_VISIBILITY
1402 const_iterator lower_bound(const key_type& __k) const
1403 {return __tree_.lower_bound(__k);}
1404 #if _LIBCPP_STD_VER > 11
1405 template <typename _K2>
1406 _LIBCPP_INLINE_VISIBILITY
1407 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1408 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
1410 template <typename _K2>
1411 _LIBCPP_INLINE_VISIBILITY
1412 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1413 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
1416 _LIBCPP_INLINE_VISIBILITY
1417 iterator upper_bound(const key_type& __k)
1418 {return __tree_.upper_bound(__k);}
1419 _LIBCPP_INLINE_VISIBILITY
1420 const_iterator upper_bound(const key_type& __k) const
1421 {return __tree_.upper_bound(__k);}
1422 #if _LIBCPP_STD_VER > 11
1423 template <typename _K2>
1424 _LIBCPP_INLINE_VISIBILITY
1425 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1426 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
1427 template <typename _K2>
1428 _LIBCPP_INLINE_VISIBILITY
1429 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1430 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
1433 _LIBCPP_INLINE_VISIBILITY
1434 pair<iterator,iterator> equal_range(const key_type& __k)
1435 {return __tree_.__equal_range_unique(__k);}
1436 _LIBCPP_INLINE_VISIBILITY
1437 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
1438 {return __tree_.__equal_range_unique(__k);}
1439 #if _LIBCPP_STD_VER > 11
1440 template <typename _K2>
1441 _LIBCPP_INLINE_VISIBILITY
1442 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
1443 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
1444 template <typename _K2>
1445 _LIBCPP_INLINE_VISIBILITY
1446 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
1447 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
1451 typedef typename __base::__node __node;
1452 typedef typename __base::__node_allocator __node_allocator;
1453 typedef typename __base::__node_pointer __node_pointer;
1454 typedef typename __base::__node_base_pointer __node_base_pointer;
1455 typedef typename __base::__parent_pointer __parent_pointer;
1457 typedef __map_node_destructor<__node_allocator> _Dp;
1458 typedef unique_ptr<__node, _Dp> __node_holder;
1460 #ifdef _LIBCPP_CXX03_LANG
1461 __node_holder __construct_node_with_key(const key_type& __k);
1466 #ifndef _LIBCPP_CXX03_LANG
1467 template <class _Key, class _Tp, class _Compare, class _Allocator>
1468 map<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a)
1469 : __tree_(_VSTD::move(__m.__tree_), typename __base::allocator_type(__a))
1471 if (__a != __m.get_allocator())
1473 const_iterator __e = cend();
1474 while (!__m.empty())
1475 __tree_.__insert_unique(__e.__i_,
1476 __m.__tree_.remove(__m.begin().__i_)->__value_.__move());
1480 template <class _Key, class _Tp, class _Compare, class _Allocator>
1482 map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k)
1484 return __tree_.__emplace_unique_key_args(__k,
1485 _VSTD::piecewise_construct,
1486 _VSTD::forward_as_tuple(__k),
1487 _VSTD::forward_as_tuple()).first->__get_value().second;
1490 template <class _Key, class _Tp, class _Compare, class _Allocator>
1492 map<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k)
1494 return __tree_.__emplace_unique_key_args(__k,
1495 _VSTD::piecewise_construct,
1496 _VSTD::forward_as_tuple(_VSTD::move(__k)),
1497 _VSTD::forward_as_tuple()).first->__get_value().second;
1500 #else // _LIBCPP_CXX03_LANG
1502 template <class _Key, class _Tp, class _Compare, class _Allocator>
1503 typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1504 map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(const key_type& __k)
1506 __node_allocator& __na = __tree_.__node_alloc();
1507 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1508 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().first), __k);
1509 __h.get_deleter().__first_constructed = true;
1510 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().second));
1511 __h.get_deleter().__second_constructed = true;
1512 return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03
1515 template <class _Key, class _Tp, class _Compare, class _Allocator>
1517 map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k)
1519 __parent_pointer __parent;
1520 __node_base_pointer& __child = __tree_.__find_equal(__parent, __k);
1521 __node_pointer __r = static_cast<__node_pointer>(__child);
1522 if (__child == nullptr)
1524 __node_holder __h = __construct_node_with_key(__k);
1525 __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
1526 __r = __h.release();
1528 return __r->__value_.__get_value().second;
1531 #endif // _LIBCPP_CXX03_LANG
1533 template <class _Key, class _Tp, class _Compare, class _Allocator>
1535 map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k)
1537 __parent_pointer __parent;
1538 __node_base_pointer& __child = __tree_.__find_equal(__parent, __k);
1539 #ifndef _LIBCPP_NO_EXCEPTIONS
1540 if (__child == nullptr)
1541 throw out_of_range("map::at: key not found");
1542 #endif // _LIBCPP_NO_EXCEPTIONS
1543 return static_cast<__node_pointer>(__child)->__value_.__get_value().second;
1546 template <class _Key, class _Tp, class _Compare, class _Allocator>
1548 map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const
1550 __parent_pointer __parent;
1551 __node_base_pointer __child = __tree_.__find_equal(__parent, __k);
1552 #ifndef _LIBCPP_NO_EXCEPTIONS
1553 if (__child == nullptr)
1554 throw out_of_range("map::at: key not found");
1555 #endif // _LIBCPP_NO_EXCEPTIONS
1556 return static_cast<__node_pointer>(__child)->__value_.__get_value().second;
1560 template <class _Key, class _Tp, class _Compare, class _Allocator>
1561 inline _LIBCPP_INLINE_VISIBILITY
1563 operator==(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1564 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1566 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
1569 template <class _Key, class _Tp, class _Compare, class _Allocator>
1570 inline _LIBCPP_INLINE_VISIBILITY
1572 operator< (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1573 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1575 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
1578 template <class _Key, class _Tp, class _Compare, class _Allocator>
1579 inline _LIBCPP_INLINE_VISIBILITY
1581 operator!=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1582 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1584 return !(__x == __y);
1587 template <class _Key, class _Tp, class _Compare, class _Allocator>
1588 inline _LIBCPP_INLINE_VISIBILITY
1590 operator> (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1591 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1596 template <class _Key, class _Tp, class _Compare, class _Allocator>
1597 inline _LIBCPP_INLINE_VISIBILITY
1599 operator>=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1600 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1602 return !(__x < __y);
1605 template <class _Key, class _Tp, class _Compare, class _Allocator>
1606 inline _LIBCPP_INLINE_VISIBILITY
1608 operator<=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1609 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1611 return !(__y < __x);
1614 template <class _Key, class _Tp, class _Compare, class _Allocator>
1615 inline _LIBCPP_INLINE_VISIBILITY
1617 swap(map<_Key, _Tp, _Compare, _Allocator>& __x,
1618 map<_Key, _Tp, _Compare, _Allocator>& __y)
1619 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
1624 #if _LIBCPP_STD_VER > 17
1625 template <class _Key, class _Tp, class _Compare, class _Allocator, class _Predicate>
1626 inline _LIBCPP_INLINE_VISIBILITY
1627 void erase_if(map<_Key, _Tp, _Compare, _Allocator>& __c, _Predicate __pred)
1628 { __libcpp_erase_if_container(__c, __pred); }
1632 template <class _Key, class _Tp, class _Compare = less<_Key>,
1633 class _Allocator = allocator<pair<const _Key, _Tp> > >
1634 class _LIBCPP_TEMPLATE_VIS multimap
1638 typedef _Key key_type;
1639 typedef _Tp mapped_type;
1640 typedef pair<const key_type, mapped_type> value_type;
1641 typedef _Compare key_compare;
1642 typedef _Allocator allocator_type;
1643 typedef value_type& reference;
1644 typedef const value_type& const_reference;
1646 static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
1647 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
1648 "Allocator::value_type must be same type as value_type");
1650 class _LIBCPP_TEMPLATE_VIS value_compare
1651 : public binary_function<value_type, value_type, bool>
1653 friend class multimap;
1657 _LIBCPP_INLINE_VISIBILITY
1658 value_compare(key_compare c) : comp(c) {}
1660 _LIBCPP_INLINE_VISIBILITY
1661 bool operator()(const value_type& __x, const value_type& __y) const
1662 {return comp(__x.first, __y.first);}
1667 typedef _VSTD::__value_type<key_type, mapped_type> __value_type;
1668 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
1669 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
1670 __value_type>::type __allocator_type;
1671 typedef __tree<__value_type, __vc, __allocator_type> __base;
1672 typedef typename __base::__node_traits __node_traits;
1673 typedef allocator_traits<allocator_type> __alloc_traits;
1678 typedef typename __alloc_traits::pointer pointer;
1679 typedef typename __alloc_traits::const_pointer const_pointer;
1680 typedef typename __alloc_traits::size_type size_type;
1681 typedef typename __alloc_traits::difference_type difference_type;
1682 typedef __map_iterator<typename __base::iterator> iterator;
1683 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
1684 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1685 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
1687 #if _LIBCPP_STD_VER > 14
1688 typedef __map_node_handle<typename __base::__node, allocator_type> node_type;
1691 template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
1692 friend class _LIBCPP_TEMPLATE_VIS map;
1693 template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
1694 friend class _LIBCPP_TEMPLATE_VIS multimap;
1696 _LIBCPP_INLINE_VISIBILITY
1699 is_nothrow_default_constructible<allocator_type>::value &&
1700 is_nothrow_default_constructible<key_compare>::value &&
1701 is_nothrow_copy_constructible<key_compare>::value)
1702 : __tree_(__vc(key_compare())) {}
1704 _LIBCPP_INLINE_VISIBILITY
1705 explicit multimap(const key_compare& __comp)
1707 is_nothrow_default_constructible<allocator_type>::value &&
1708 is_nothrow_copy_constructible<key_compare>::value)
1709 : __tree_(__vc(__comp)) {}
1711 _LIBCPP_INLINE_VISIBILITY
1712 explicit multimap(const key_compare& __comp, const allocator_type& __a)
1713 : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {}
1715 template <class _InputIterator>
1716 _LIBCPP_INLINE_VISIBILITY
1717 multimap(_InputIterator __f, _InputIterator __l,
1718 const key_compare& __comp = key_compare())
1719 : __tree_(__vc(__comp))
1724 template <class _InputIterator>
1725 _LIBCPP_INLINE_VISIBILITY
1726 multimap(_InputIterator __f, _InputIterator __l,
1727 const key_compare& __comp, const allocator_type& __a)
1728 : __tree_(__vc(__comp), typename __base::allocator_type(__a))
1733 #if _LIBCPP_STD_VER > 11
1734 template <class _InputIterator>
1735 _LIBCPP_INLINE_VISIBILITY
1736 multimap(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
1737 : multimap(__f, __l, key_compare(), __a) {}
1740 _LIBCPP_INLINE_VISIBILITY
1741 multimap(const multimap& __m)
1742 : __tree_(__m.__tree_.value_comp(),
1743 __alloc_traits::select_on_container_copy_construction(__m.__tree_.__alloc()))
1745 insert(__m.begin(), __m.end());
1748 _LIBCPP_INLINE_VISIBILITY
1749 multimap& operator=(const multimap& __m)
1751 #ifndef _LIBCPP_CXX03_LANG
1752 __tree_ = __m.__tree_;
1756 __tree_.value_comp() = __m.__tree_.value_comp();
1757 __tree_.__copy_assign_alloc(__m.__tree_);
1758 insert(__m.begin(), __m.end());
1764 #ifndef _LIBCPP_CXX03_LANG
1766 _LIBCPP_INLINE_VISIBILITY
1767 multimap(multimap&& __m)
1768 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
1769 : __tree_(_VSTD::move(__m.__tree_))
1773 multimap(multimap&& __m, const allocator_type& __a);
1775 _LIBCPP_INLINE_VISIBILITY
1776 multimap& operator=(multimap&& __m)
1777 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
1779 __tree_ = _VSTD::move(__m.__tree_);
1783 _LIBCPP_INLINE_VISIBILITY
1784 multimap(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
1785 : __tree_(__vc(__comp))
1787 insert(__il.begin(), __il.end());
1790 _LIBCPP_INLINE_VISIBILITY
1791 multimap(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
1792 : __tree_(__vc(__comp), typename __base::allocator_type(__a))
1794 insert(__il.begin(), __il.end());
1797 #if _LIBCPP_STD_VER > 11
1798 _LIBCPP_INLINE_VISIBILITY
1799 multimap(initializer_list<value_type> __il, const allocator_type& __a)
1800 : multimap(__il, key_compare(), __a) {}
1803 _LIBCPP_INLINE_VISIBILITY
1804 multimap& operator=(initializer_list<value_type> __il)
1806 __tree_.__assign_multi(__il.begin(), __il.end());
1810 #endif // _LIBCPP_CXX03_LANG
1812 _LIBCPP_INLINE_VISIBILITY
1813 explicit multimap(const allocator_type& __a)
1814 : __tree_(typename __base::allocator_type(__a))
1818 _LIBCPP_INLINE_VISIBILITY
1819 multimap(const multimap& __m, const allocator_type& __a)
1820 : __tree_(__m.__tree_.value_comp(), typename __base::allocator_type(__a))
1822 insert(__m.begin(), __m.end());
1825 _LIBCPP_INLINE_VISIBILITY
1826 iterator begin() _NOEXCEPT {return __tree_.begin();}
1827 _LIBCPP_INLINE_VISIBILITY
1828 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
1829 _LIBCPP_INLINE_VISIBILITY
1830 iterator end() _NOEXCEPT {return __tree_.end();}
1831 _LIBCPP_INLINE_VISIBILITY
1832 const_iterator end() const _NOEXCEPT {return __tree_.end();}
1834 _LIBCPP_INLINE_VISIBILITY
1835 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
1836 _LIBCPP_INLINE_VISIBILITY
1837 const_reverse_iterator rbegin() const _NOEXCEPT
1838 {return const_reverse_iterator(end());}
1839 _LIBCPP_INLINE_VISIBILITY
1840 reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
1841 _LIBCPP_INLINE_VISIBILITY
1842 const_reverse_iterator rend() const _NOEXCEPT
1843 {return const_reverse_iterator(begin());}
1845 _LIBCPP_INLINE_VISIBILITY
1846 const_iterator cbegin() const _NOEXCEPT {return begin();}
1847 _LIBCPP_INLINE_VISIBILITY
1848 const_iterator cend() const _NOEXCEPT {return end();}
1849 _LIBCPP_INLINE_VISIBILITY
1850 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
1851 _LIBCPP_INLINE_VISIBILITY
1852 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
1854 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1855 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
1856 _LIBCPP_INLINE_VISIBILITY
1857 size_type size() const _NOEXCEPT {return __tree_.size();}
1858 _LIBCPP_INLINE_VISIBILITY
1859 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
1861 _LIBCPP_INLINE_VISIBILITY
1862 allocator_type get_allocator() const _NOEXCEPT {return allocator_type(__tree_.__alloc());}
1863 _LIBCPP_INLINE_VISIBILITY
1864 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
1865 _LIBCPP_INLINE_VISIBILITY
1866 value_compare value_comp() const
1867 {return value_compare(__tree_.value_comp().key_comp());}
1869 #ifndef _LIBCPP_CXX03_LANG
1871 template <class ..._Args>
1872 _LIBCPP_INLINE_VISIBILITY
1873 iterator emplace(_Args&& ...__args) {
1874 return __tree_.__emplace_multi(_VSTD::forward<_Args>(__args)...);
1877 template <class ..._Args>
1878 _LIBCPP_INLINE_VISIBILITY
1879 iterator emplace_hint(const_iterator __p, _Args&& ...__args) {
1880 return __tree_.__emplace_hint_multi(__p.__i_, _VSTD::forward<_Args>(__args)...);
1883 template <class _Pp,
1884 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
1885 _LIBCPP_INLINE_VISIBILITY
1886 iterator insert(_Pp&& __p)
1887 {return __tree_.__insert_multi(_VSTD::forward<_Pp>(__p));}
1889 template <class _Pp,
1890 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
1891 _LIBCPP_INLINE_VISIBILITY
1892 iterator insert(const_iterator __pos, _Pp&& __p)
1893 {return __tree_.__insert_multi(__pos.__i_, _VSTD::forward<_Pp>(__p));}
1895 _LIBCPP_INLINE_VISIBILITY
1896 iterator insert(value_type&& __v)
1897 {return __tree_.__insert_multi(_VSTD::move(__v));}
1899 _LIBCPP_INLINE_VISIBILITY
1900 iterator insert(const_iterator __p, value_type&& __v)
1901 {return __tree_.__insert_multi(__p.__i_, _VSTD::move(__v));}
1904 _LIBCPP_INLINE_VISIBILITY
1905 void insert(initializer_list<value_type> __il)
1906 {insert(__il.begin(), __il.end());}
1908 #endif // _LIBCPP_CXX03_LANG
1910 _LIBCPP_INLINE_VISIBILITY
1911 iterator insert(const value_type& __v) {return __tree_.__insert_multi(__v);}
1913 _LIBCPP_INLINE_VISIBILITY
1914 iterator insert(const_iterator __p, const value_type& __v)
1915 {return __tree_.__insert_multi(__p.__i_, __v);}
1917 template <class _InputIterator>
1918 _LIBCPP_INLINE_VISIBILITY
1919 void insert(_InputIterator __f, _InputIterator __l)
1921 for (const_iterator __e = cend(); __f != __l; ++__f)
1922 __tree_.__insert_multi(__e.__i_, *__f);
1925 _LIBCPP_INLINE_VISIBILITY
1926 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
1927 _LIBCPP_INLINE_VISIBILITY
1928 iterator erase(iterator __p) {return __tree_.erase(__p.__i_);}
1929 _LIBCPP_INLINE_VISIBILITY
1930 size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
1931 _LIBCPP_INLINE_VISIBILITY
1932 iterator erase(const_iterator __f, const_iterator __l)
1933 {return __tree_.erase(__f.__i_, __l.__i_);}
1935 #if _LIBCPP_STD_VER > 14
1936 _LIBCPP_INLINE_VISIBILITY
1937 iterator insert(node_type&& __nh)
1939 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1940 "node_type with incompatible allocator passed to multimap::insert()");
1941 return __tree_.template __node_handle_insert_multi<node_type>(
1944 _LIBCPP_INLINE_VISIBILITY
1945 iterator insert(const_iterator __hint, node_type&& __nh)
1947 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1948 "node_type with incompatible allocator passed to multimap::insert()");
1949 return __tree_.template __node_handle_insert_multi<node_type>(
1950 __hint.__i_, _VSTD::move(__nh));
1952 _LIBCPP_INLINE_VISIBILITY
1953 node_type extract(key_type const& __key)
1955 return __tree_.template __node_handle_extract<node_type>(__key);
1957 _LIBCPP_INLINE_VISIBILITY
1958 node_type extract(const_iterator __it)
1960 return __tree_.template __node_handle_extract<node_type>(
1963 template <class _Compare2>
1964 _LIBCPP_INLINE_VISIBILITY
1965 void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>& __source)
1967 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1968 "merging container with incompatible allocator");
1969 return __tree_.__node_handle_merge_multi(__source.__tree_);
1971 template <class _Compare2>
1972 _LIBCPP_INLINE_VISIBILITY
1973 void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>&& __source)
1975 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1976 "merging container with incompatible allocator");
1977 return __tree_.__node_handle_merge_multi(__source.__tree_);
1979 template <class _Compare2>
1980 _LIBCPP_INLINE_VISIBILITY
1981 void merge(map<key_type, mapped_type, _Compare2, allocator_type>& __source)
1983 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1984 "merging container with incompatible allocator");
1985 return __tree_.__node_handle_merge_multi(__source.__tree_);
1987 template <class _Compare2>
1988 _LIBCPP_INLINE_VISIBILITY
1989 void merge(map<key_type, mapped_type, _Compare2, allocator_type>&& __source)
1991 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1992 "merging container with incompatible allocator");
1993 return __tree_.__node_handle_merge_multi(__source.__tree_);
1997 _LIBCPP_INLINE_VISIBILITY
1998 void clear() _NOEXCEPT {__tree_.clear();}
2000 _LIBCPP_INLINE_VISIBILITY
2001 void swap(multimap& __m)
2002 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
2003 {__tree_.swap(__m.__tree_);}
2005 _LIBCPP_INLINE_VISIBILITY
2006 iterator find(const key_type& __k) {return __tree_.find(__k);}
2007 _LIBCPP_INLINE_VISIBILITY
2008 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
2009 #if _LIBCPP_STD_VER > 11
2010 template <typename _K2>
2011 _LIBCPP_INLINE_VISIBILITY
2012 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
2013 find(const _K2& __k) {return __tree_.find(__k);}
2014 template <typename _K2>
2015 _LIBCPP_INLINE_VISIBILITY
2016 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
2017 find(const _K2& __k) const {return __tree_.find(__k);}
2020 _LIBCPP_INLINE_VISIBILITY
2021 size_type count(const key_type& __k) const
2022 {return __tree_.__count_multi(__k);}
2023 #if _LIBCPP_STD_VER > 11
2024 template <typename _K2>
2025 _LIBCPP_INLINE_VISIBILITY
2026 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
2027 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
2029 _LIBCPP_INLINE_VISIBILITY
2030 iterator lower_bound(const key_type& __k)
2031 {return __tree_.lower_bound(__k);}
2032 _LIBCPP_INLINE_VISIBILITY
2033 const_iterator lower_bound(const key_type& __k) const
2034 {return __tree_.lower_bound(__k);}
2035 #if _LIBCPP_STD_VER > 11
2036 template <typename _K2>
2037 _LIBCPP_INLINE_VISIBILITY
2038 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
2039 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
2041 template <typename _K2>
2042 _LIBCPP_INLINE_VISIBILITY
2043 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
2044 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
2047 _LIBCPP_INLINE_VISIBILITY
2048 iterator upper_bound(const key_type& __k)
2049 {return __tree_.upper_bound(__k);}
2050 _LIBCPP_INLINE_VISIBILITY
2051 const_iterator upper_bound(const key_type& __k) const
2052 {return __tree_.upper_bound(__k);}
2053 #if _LIBCPP_STD_VER > 11
2054 template <typename _K2>
2055 _LIBCPP_INLINE_VISIBILITY
2056 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
2057 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
2058 template <typename _K2>
2059 _LIBCPP_INLINE_VISIBILITY
2060 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
2061 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
2064 _LIBCPP_INLINE_VISIBILITY
2065 pair<iterator,iterator> equal_range(const key_type& __k)
2066 {return __tree_.__equal_range_multi(__k);}
2067 _LIBCPP_INLINE_VISIBILITY
2068 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
2069 {return __tree_.__equal_range_multi(__k);}
2070 #if _LIBCPP_STD_VER > 11
2071 template <typename _K2>
2072 _LIBCPP_INLINE_VISIBILITY
2073 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
2074 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
2075 template <typename _K2>
2076 _LIBCPP_INLINE_VISIBILITY
2077 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
2078 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
2082 typedef typename __base::__node __node;
2083 typedef typename __base::__node_allocator __node_allocator;
2084 typedef typename __base::__node_pointer __node_pointer;
2086 typedef __map_node_destructor<__node_allocator> _Dp;
2087 typedef unique_ptr<__node, _Dp> __node_holder;
2090 #ifndef _LIBCPP_CXX03_LANG
2091 template <class _Key, class _Tp, class _Compare, class _Allocator>
2092 multimap<_Key, _Tp, _Compare, _Allocator>::multimap(multimap&& __m, const allocator_type& __a)
2093 : __tree_(_VSTD::move(__m.__tree_), typename __base::allocator_type(__a))
2095 if (__a != __m.get_allocator())
2097 const_iterator __e = cend();
2098 while (!__m.empty())
2099 __tree_.__insert_multi(__e.__i_,
2100 _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_.__move()));
2105 template <class _Key, class _Tp, class _Compare, class _Allocator>
2106 inline _LIBCPP_INLINE_VISIBILITY
2108 operator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2109 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2111 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
2114 template <class _Key, class _Tp, class _Compare, class _Allocator>
2115 inline _LIBCPP_INLINE_VISIBILITY
2117 operator< (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2118 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2120 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
2123 template <class _Key, class _Tp, class _Compare, class _Allocator>
2124 inline _LIBCPP_INLINE_VISIBILITY
2126 operator!=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2127 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2129 return !(__x == __y);
2132 template <class _Key, class _Tp, class _Compare, class _Allocator>
2133 inline _LIBCPP_INLINE_VISIBILITY
2135 operator> (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2136 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2141 template <class _Key, class _Tp, class _Compare, class _Allocator>
2142 inline _LIBCPP_INLINE_VISIBILITY
2144 operator>=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2145 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2147 return !(__x < __y);
2150 template <class _Key, class _Tp, class _Compare, class _Allocator>
2151 inline _LIBCPP_INLINE_VISIBILITY
2153 operator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2154 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2156 return !(__y < __x);
2159 template <class _Key, class _Tp, class _Compare, class _Allocator>
2160 inline _LIBCPP_INLINE_VISIBILITY
2162 swap(multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2163 multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2164 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
2169 #if _LIBCPP_STD_VER > 17
2170 template <class _Key, class _Tp, class _Compare, class _Allocator, class _Predicate>
2171 inline _LIBCPP_INLINE_VISIBILITY
2172 void erase_if(multimap<_Key, _Tp, _Compare, _Allocator>& __c, _Predicate __pred)
2173 { __libcpp_erase_if_container(__c, __pred); }
2176 _LIBCPP_END_NAMESPACE_STD
2178 #endif // _LIBCPP_MAP