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;
45 : public binary_function<value_type, value_type, bool>
51 value_compare(key_compare c);
53 bool operator()(const value_type& x, const value_type& y) const;
56 // construct/copy/destroy:
59 is_nothrow_default_constructible<allocator_type>::value &&
60 is_nothrow_default_constructible<key_compare>::value &&
61 is_nothrow_copy_constructible<key_compare>::value);
62 explicit map(const key_compare& comp);
63 map(const key_compare& comp, const allocator_type& a);
64 template <class InputIterator>
65 map(InputIterator first, InputIterator last,
66 const key_compare& comp = key_compare());
67 template <class InputIterator>
68 map(InputIterator first, InputIterator last,
69 const key_compare& comp, const allocator_type& a);
73 is_nothrow_move_constructible<allocator_type>::value &&
74 is_nothrow_move_constructible<key_compare>::value);
75 explicit map(const allocator_type& a);
76 map(const map& m, const allocator_type& a);
77 map(map&& m, const allocator_type& a);
78 map(initializer_list<value_type> il, const key_compare& comp = key_compare());
79 map(initializer_list<value_type> il, const key_compare& comp, const allocator_type& a);
80 template <class InputIterator>
81 map(InputIterator first, InputIterator last, const allocator_type& a)
82 : map(first, last, Compare(), a) {} // C++14
83 map(initializer_list<value_type> il, const allocator_type& a)
84 : map(il, Compare(), a) {} // C++14
87 map& operator=(const map& m);
88 map& operator=(map&& m)
90 allocator_type::propagate_on_container_move_assignment::value &&
91 is_nothrow_move_assignable<allocator_type>::value &&
92 is_nothrow_move_assignable<key_compare>::value);
93 map& operator=(initializer_list<value_type> il);
96 iterator begin() noexcept;
97 const_iterator begin() const noexcept;
98 iterator end() noexcept;
99 const_iterator end() const noexcept;
101 reverse_iterator rbegin() noexcept;
102 const_reverse_iterator rbegin() const noexcept;
103 reverse_iterator rend() noexcept;
104 const_reverse_iterator rend() const noexcept;
106 const_iterator cbegin() const noexcept;
107 const_iterator cend() const noexcept;
108 const_reverse_iterator crbegin() const noexcept;
109 const_reverse_iterator crend() const noexcept;
112 bool empty() const noexcept;
113 size_type size() const noexcept;
114 size_type max_size() const noexcept;
117 mapped_type& operator[](const key_type& k);
118 mapped_type& operator[](key_type&& k);
120 mapped_type& at(const key_type& k);
121 const mapped_type& at(const key_type& k) const;
124 template <class... Args>
125 pair<iterator, bool> emplace(Args&&... args);
126 template <class... Args>
127 iterator emplace_hint(const_iterator position, Args&&... args);
128 pair<iterator, bool> insert(const value_type& v);
130 pair<iterator, bool> insert(P&& p);
131 iterator insert(const_iterator position, const value_type& v);
133 iterator insert(const_iterator position, P&& p);
134 template <class InputIterator>
135 void insert(InputIterator first, InputIterator last);
136 void insert(initializer_list<value_type> il);
138 template <class... Args>
139 pair<iterator, bool> try_emplace(const key_type& k, Args&&... args); // C++17
140 template <class... Args>
141 pair<iterator, bool> try_emplace(key_type&& k, Args&&... args); // C++17
142 template <class... Args>
143 iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args); // C++17
144 template <class... Args>
145 iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args); // C++17
147 pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj); // C++17
149 pair<iterator, bool> insert_or_assign(key_type&& k, M&& obj); // C++17
151 iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj); // C++17
153 iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj); // C++17
155 iterator erase(const_iterator position);
156 iterator erase(iterator position); // C++14
157 size_type erase(const key_type& k);
158 iterator erase(const_iterator first, const_iterator last);
159 void clear() noexcept;
162 noexcept(allocator_traits<allocator_type>::is_always_equal::value &&
163 __is_nothrow_swappable<key_compare>::value); // C++17
166 allocator_type get_allocator() const noexcept;
167 key_compare key_comp() const;
168 value_compare value_comp() const;
171 iterator find(const key_type& k);
172 const_iterator find(const key_type& k) const;
174 iterator find(const K& x); // C++14
176 const_iterator find(const K& x) const; // C++14
178 size_type count(const K& x) const; // C++14
180 size_type count(const key_type& k) const;
181 iterator lower_bound(const key_type& k);
182 const_iterator lower_bound(const key_type& k) const;
184 iterator lower_bound(const K& x); // C++14
186 const_iterator lower_bound(const K& x) const; // C++14
188 iterator upper_bound(const key_type& k);
189 const_iterator upper_bound(const key_type& k) const;
191 iterator upper_bound(const K& x); // C++14
193 const_iterator upper_bound(const K& x) const; // C++14
195 pair<iterator,iterator> equal_range(const key_type& k);
196 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
198 pair<iterator,iterator> equal_range(const K& x); // C++14
200 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
203 template <class Key, class T, class Compare, class Allocator>
205 operator==(const map<Key, T, Compare, Allocator>& x,
206 const map<Key, T, Compare, Allocator>& y);
208 template <class Key, class T, class Compare, class Allocator>
210 operator< (const map<Key, T, Compare, Allocator>& x,
211 const map<Key, T, Compare, Allocator>& y);
213 template <class Key, class T, class Compare, class Allocator>
215 operator!=(const map<Key, T, Compare, Allocator>& x,
216 const map<Key, T, Compare, Allocator>& y);
218 template <class Key, class T, class Compare, class Allocator>
220 operator> (const map<Key, T, Compare, Allocator>& x,
221 const map<Key, T, Compare, Allocator>& y);
223 template <class Key, class T, class Compare, class Allocator>
225 operator>=(const map<Key, T, Compare, Allocator>& x,
226 const map<Key, T, Compare, Allocator>& y);
228 template <class Key, class T, class Compare, class Allocator>
230 operator<=(const map<Key, T, Compare, Allocator>& x,
231 const map<Key, T, Compare, Allocator>& y);
233 // specialized algorithms:
234 template <class Key, class T, class Compare, class Allocator>
236 swap(map<Key, T, Compare, Allocator>& x, map<Key, T, Compare, Allocator>& y)
237 noexcept(noexcept(x.swap(y)));
239 template <class Key, class T, class Compare = less<Key>,
240 class Allocator = allocator<pair<const Key, T>>>
245 typedef Key key_type;
246 typedef T mapped_type;
247 typedef pair<const key_type,mapped_type> value_type;
248 typedef Compare key_compare;
249 typedef Allocator allocator_type;
250 typedef typename allocator_type::reference reference;
251 typedef typename allocator_type::const_reference const_reference;
252 typedef typename allocator_type::size_type size_type;
253 typedef typename allocator_type::difference_type difference_type;
254 typedef typename allocator_type::pointer pointer;
255 typedef typename allocator_type::const_pointer const_pointer;
257 typedef implementation-defined iterator;
258 typedef implementation-defined const_iterator;
259 typedef std::reverse_iterator<iterator> reverse_iterator;
260 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
263 : public binary_function<value_type,value_type,bool>
265 friend class multimap;
268 value_compare(key_compare c);
270 bool operator()(const value_type& x, const value_type& y) const;
273 // construct/copy/destroy:
276 is_nothrow_default_constructible<allocator_type>::value &&
277 is_nothrow_default_constructible<key_compare>::value &&
278 is_nothrow_copy_constructible<key_compare>::value);
279 explicit multimap(const key_compare& comp);
280 multimap(const key_compare& comp, const allocator_type& a);
281 template <class InputIterator>
282 multimap(InputIterator first, InputIterator last, const key_compare& comp);
283 template <class InputIterator>
284 multimap(InputIterator first, InputIterator last, const key_compare& comp,
285 const allocator_type& a);
286 multimap(const multimap& m);
287 multimap(multimap&& m)
289 is_nothrow_move_constructible<allocator_type>::value &&
290 is_nothrow_move_constructible<key_compare>::value);
291 explicit multimap(const allocator_type& a);
292 multimap(const multimap& m, const allocator_type& a);
293 multimap(multimap&& m, const allocator_type& a);
294 multimap(initializer_list<value_type> il, const key_compare& comp = key_compare());
295 multimap(initializer_list<value_type> il, const key_compare& comp,
296 const allocator_type& a);
297 template <class InputIterator>
298 multimap(InputIterator first, InputIterator last, const allocator_type& a)
299 : multimap(first, last, Compare(), a) {} // C++14
300 multimap(initializer_list<value_type> il, const allocator_type& a)
301 : multimap(il, Compare(), a) {} // C++14
304 multimap& operator=(const multimap& m);
305 multimap& operator=(multimap&& m)
307 allocator_type::propagate_on_container_move_assignment::value &&
308 is_nothrow_move_assignable<allocator_type>::value &&
309 is_nothrow_move_assignable<key_compare>::value);
310 multimap& operator=(initializer_list<value_type> il);
313 iterator begin() noexcept;
314 const_iterator begin() const noexcept;
315 iterator end() noexcept;
316 const_iterator end() const noexcept;
318 reverse_iterator rbegin() noexcept;
319 const_reverse_iterator rbegin() const noexcept;
320 reverse_iterator rend() noexcept;
321 const_reverse_iterator rend() const noexcept;
323 const_iterator cbegin() const noexcept;
324 const_iterator cend() const noexcept;
325 const_reverse_iterator crbegin() const noexcept;
326 const_reverse_iterator crend() const noexcept;
329 bool empty() const noexcept;
330 size_type size() const noexcept;
331 size_type max_size() const noexcept;
334 template <class... Args>
335 iterator emplace(Args&&... args);
336 template <class... Args>
337 iterator emplace_hint(const_iterator position, Args&&... args);
338 iterator insert(const value_type& v);
340 iterator insert(P&& p);
341 iterator insert(const_iterator position, const value_type& v);
343 iterator insert(const_iterator position, P&& p);
344 template <class InputIterator>
345 void insert(InputIterator first, InputIterator last);
346 void insert(initializer_list<value_type> il);
348 iterator erase(const_iterator position);
349 iterator erase(iterator position); // C++14
350 size_type erase(const key_type& k);
351 iterator erase(const_iterator first, const_iterator last);
352 void clear() noexcept;
354 void swap(multimap& m)
355 noexcept(allocator_traits<allocator_type>::is_always_equal::value &&
356 __is_nothrow_swappable<key_compare>::value); // C++17
359 allocator_type get_allocator() const noexcept;
360 key_compare key_comp() const;
361 value_compare value_comp() const;
364 iterator find(const key_type& k);
365 const_iterator find(const key_type& k) const;
367 iterator find(const K& x); // C++14
369 const_iterator find(const K& x) const; // C++14
371 size_type count(const K& x) const; // C++14
373 size_type count(const key_type& k) const;
374 iterator lower_bound(const key_type& k);
375 const_iterator lower_bound(const key_type& k) const;
377 iterator lower_bound(const K& x); // C++14
379 const_iterator lower_bound(const K& x) const; // C++14
381 iterator upper_bound(const key_type& k);
382 const_iterator upper_bound(const key_type& k) const;
384 iterator upper_bound(const K& x); // C++14
386 const_iterator upper_bound(const K& x) const; // C++14
388 pair<iterator,iterator> equal_range(const key_type& k);
389 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
391 pair<iterator,iterator> equal_range(const K& x); // C++14
393 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
396 template <class Key, class T, class Compare, class Allocator>
398 operator==(const multimap<Key, T, Compare, Allocator>& x,
399 const multimap<Key, T, Compare, Allocator>& y);
401 template <class Key, class T, class Compare, class Allocator>
403 operator< (const multimap<Key, T, Compare, Allocator>& x,
404 const multimap<Key, T, Compare, Allocator>& y);
406 template <class Key, class T, class Compare, class Allocator>
408 operator!=(const multimap<Key, T, Compare, Allocator>& x,
409 const multimap<Key, T, Compare, Allocator>& y);
411 template <class Key, class T, class Compare, class Allocator>
413 operator> (const multimap<Key, T, Compare, Allocator>& x,
414 const multimap<Key, T, Compare, Allocator>& y);
416 template <class Key, class T, class Compare, class Allocator>
418 operator>=(const multimap<Key, T, Compare, Allocator>& x,
419 const multimap<Key, T, Compare, Allocator>& y);
421 template <class Key, class T, class Compare, class Allocator>
423 operator<=(const multimap<Key, T, Compare, Allocator>& x,
424 const multimap<Key, T, Compare, Allocator>& y);
426 // specialized algorithms:
427 template <class Key, class T, class Compare, class Allocator>
429 swap(multimap<Key, T, Compare, Allocator>& x,
430 multimap<Key, T, Compare, Allocator>& y)
431 noexcept(noexcept(x.swap(y)));
442 #include <functional>
443 #include <initializer_list>
444 #include <type_traits>
446 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
447 #pragma GCC system_header
450 _LIBCPP_BEGIN_NAMESPACE_STD
452 template <class _Key, class _CP, class _Compare,
453 bool = is_empty<_Compare>::value && !__libcpp_is_final<_Compare>::value
455 class __map_value_compare
459 _LIBCPP_INLINE_VISIBILITY
460 __map_value_compare()
461 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
463 _LIBCPP_INLINE_VISIBILITY
464 __map_value_compare(_Compare c)
465 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
467 _LIBCPP_INLINE_VISIBILITY
468 const _Compare& key_comp() const _NOEXCEPT {return *this;}
469 _LIBCPP_INLINE_VISIBILITY
470 bool operator()(const _CP& __x, const _CP& __y) const
471 {return static_cast<const _Compare&>(*this)(__x.__cc.first, __y.__cc.first);}
472 _LIBCPP_INLINE_VISIBILITY
473 bool operator()(const _CP& __x, const _Key& __y) const
474 {return static_cast<const _Compare&>(*this)(__x.__cc.first, __y);}
475 _LIBCPP_INLINE_VISIBILITY
476 bool operator()(const _Key& __x, const _CP& __y) const
477 {return static_cast<const _Compare&>(*this)(__x, __y.__cc.first);}
478 void swap(__map_value_compare&__y)
479 _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value)
482 swap(static_cast<const _Compare&>(*this), static_cast<const _Compare&>(__y));
485 #if _LIBCPP_STD_VER > 11
486 template <typename _K2>
487 _LIBCPP_INLINE_VISIBILITY
488 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
489 operator () ( const _K2& __x, const _CP& __y ) const
490 {return static_cast<const _Compare&>(*this) (__x, __y.__cc.first);}
492 template <typename _K2>
493 _LIBCPP_INLINE_VISIBILITY
494 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
495 operator () (const _CP& __x, const _K2& __y) const
496 {return static_cast<const _Compare&>(*this) (__x.__cc.first, __y);}
500 template <class _Key, class _CP, class _Compare>
501 class __map_value_compare<_Key, _CP, _Compare, false>
506 _LIBCPP_INLINE_VISIBILITY
507 __map_value_compare()
508 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
510 _LIBCPP_INLINE_VISIBILITY
511 __map_value_compare(_Compare c)
512 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
514 _LIBCPP_INLINE_VISIBILITY
515 const _Compare& key_comp() const _NOEXCEPT {return comp;}
517 _LIBCPP_INLINE_VISIBILITY
518 bool operator()(const _CP& __x, const _CP& __y) const
519 {return comp(__x.__cc.first, __y.__cc.first);}
520 _LIBCPP_INLINE_VISIBILITY
521 bool operator()(const _CP& __x, const _Key& __y) const
522 {return comp(__x.__cc.first, __y);}
523 _LIBCPP_INLINE_VISIBILITY
524 bool operator()(const _Key& __x, const _CP& __y) const
525 {return comp(__x, __y.__cc.first);}
526 void swap(__map_value_compare&__y)
527 _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value)
530 swap(comp, __y.comp);
533 #if _LIBCPP_STD_VER > 11
534 template <typename _K2>
535 _LIBCPP_INLINE_VISIBILITY
536 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
537 operator () ( const _K2& __x, const _CP& __y ) const
538 {return comp (__x, __y.__cc.first);}
540 template <typename _K2>
541 _LIBCPP_INLINE_VISIBILITY
542 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
543 operator () (const _CP& __x, const _K2& __y) const
544 {return comp (__x.__cc.first, __y);}
548 template <class _Key, class _CP, class _Compare, bool __b>
549 inline _LIBCPP_INLINE_VISIBILITY
551 swap(__map_value_compare<_Key, _CP, _Compare, __b>& __x,
552 __map_value_compare<_Key, _CP, _Compare, __b>& __y)
553 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
558 template <class _Allocator>
559 class __map_node_destructor
561 typedef _Allocator allocator_type;
562 typedef allocator_traits<allocator_type> __alloc_traits;
563 typedef typename __alloc_traits::value_type::value_type value_type;
565 typedef typename __alloc_traits::pointer pointer;
567 typedef typename value_type::value_type::first_type first_type;
568 typedef typename value_type::value_type::second_type second_type;
570 allocator_type& __na_;
572 __map_node_destructor& operator=(const __map_node_destructor&);
575 bool __first_constructed;
576 bool __second_constructed;
578 _LIBCPP_INLINE_VISIBILITY
579 explicit __map_node_destructor(allocator_type& __na) _NOEXCEPT
581 __first_constructed(false),
582 __second_constructed(false)
585 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
586 _LIBCPP_INLINE_VISIBILITY
587 __map_node_destructor(__tree_node_destructor<allocator_type>&& __x) _NOEXCEPT
589 __first_constructed(__x.__value_constructed),
590 __second_constructed(__x.__value_constructed)
592 __x.__value_constructed = false;
594 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
596 _LIBCPP_INLINE_VISIBILITY
597 void operator()(pointer __p) _NOEXCEPT
599 if (__second_constructed)
600 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.second));
601 if (__first_constructed)
602 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.first));
604 __alloc_traits::deallocate(__na_, __p, 1);
608 template <class _Key, class _Tp, class _Compare, class _Allocator>
610 template <class _Key, class _Tp, class _Compare, class _Allocator>
612 template <class _TreeIterator> class __map_const_iterator;
614 #if __cplusplus >= 201103L
616 template <class _Key, class _Tp>
619 typedef _Key key_type;
620 typedef _Tp mapped_type;
621 typedef pair<const key_type, mapped_type> value_type;
622 typedef pair<key_type, mapped_type> __nc_value_type;
625 __nc_value_type __nc;
627 template <class ..._Args>
628 _LIBCPP_INLINE_VISIBILITY
629 __value_type(_Args&& ...__args)
630 : __cc(std::forward<_Args>(__args)...) {}
632 _LIBCPP_INLINE_VISIBILITY
633 __value_type(const __value_type& __v)
636 _LIBCPP_INLINE_VISIBILITY
637 __value_type(__value_type& __v)
640 _LIBCPP_INLINE_VISIBILITY
641 __value_type(__value_type&& __v)
642 : __nc(std::move(__v.__nc)) {}
644 _LIBCPP_INLINE_VISIBILITY
645 __value_type& operator=(const __value_type& __v)
646 {__nc = __v.__cc; return *this;}
648 _LIBCPP_INLINE_VISIBILITY
649 __value_type& operator=(__value_type&& __v)
650 {__nc = std::move(__v.__nc); return *this;}
652 _LIBCPP_INLINE_VISIBILITY
653 ~__value_type() {__cc.~value_type();}
658 template <class _Key, class _Tp>
661 typedef _Key key_type;
662 typedef _Tp mapped_type;
663 typedef pair<const key_type, mapped_type> value_type;
667 _LIBCPP_INLINE_VISIBILITY
671 _LIBCPP_INLINE_VISIBILITY
672 __value_type(const _A0& __a0)
675 template <class _A0, class _A1>
676 _LIBCPP_INLINE_VISIBILITY
677 __value_type(const _A0& __a0, const _A1& __a1)
678 : __cc(__a0, __a1) {}
684 struct __extract_key_value_types;
686 template <class _Key, class _Tp>
687 struct __extract_key_value_types<__value_type<_Key, _Tp> >
689 typedef _Key const __key_type;
690 typedef _Tp __mapped_type;
693 template <class _TreeIterator>
694 class _LIBCPP_TYPE_VIS_ONLY __map_iterator
698 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
699 typedef typename _TreeIterator::value_type __value_type;
700 typedef typename __extract_key_value_types<__value_type>::__key_type __key_type;
701 typedef typename __extract_key_value_types<__value_type>::__mapped_type __mapped_type;
703 typedef bidirectional_iterator_tag iterator_category;
704 typedef pair<__key_type, __mapped_type> value_type;
705 typedef typename _TreeIterator::difference_type difference_type;
706 typedef value_type& reference;
707 typedef typename __pointer_traits::template
708 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
711 rebind<value_type>::other
715 _LIBCPP_INLINE_VISIBILITY
716 __map_iterator() _NOEXCEPT {}
718 _LIBCPP_INLINE_VISIBILITY
719 __map_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
721 _LIBCPP_INLINE_VISIBILITY
722 reference operator*() const {return __i_->__cc;}
723 _LIBCPP_INLINE_VISIBILITY
724 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
726 _LIBCPP_INLINE_VISIBILITY
727 __map_iterator& operator++() {++__i_; return *this;}
728 _LIBCPP_INLINE_VISIBILITY
729 __map_iterator operator++(int)
731 __map_iterator __t(*this);
736 _LIBCPP_INLINE_VISIBILITY
737 __map_iterator& operator--() {--__i_; return *this;}
738 _LIBCPP_INLINE_VISIBILITY
739 __map_iterator operator--(int)
741 __map_iterator __t(*this);
746 friend _LIBCPP_INLINE_VISIBILITY
747 bool operator==(const __map_iterator& __x, const __map_iterator& __y)
748 {return __x.__i_ == __y.__i_;}
750 _LIBCPP_INLINE_VISIBILITY
751 bool operator!=(const __map_iterator& __x, const __map_iterator& __y)
752 {return __x.__i_ != __y.__i_;}
754 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY map;
755 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY multimap;
756 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __map_const_iterator;
759 template <class _TreeIterator>
760 class _LIBCPP_TYPE_VIS_ONLY __map_const_iterator
764 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
765 typedef typename _TreeIterator::value_type __value_type;
766 typedef typename __extract_key_value_types<__value_type>::__key_type __key_type;
767 typedef typename __extract_key_value_types<__value_type>::__mapped_type __mapped_type;
769 typedef bidirectional_iterator_tag iterator_category;
770 typedef pair<__key_type, __mapped_type> value_type;
771 typedef typename _TreeIterator::difference_type difference_type;
772 typedef const value_type& reference;
773 typedef typename __pointer_traits::template
774 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
775 rebind<const value_type>
777 rebind<const value_type>::other
781 _LIBCPP_INLINE_VISIBILITY
782 __map_const_iterator() _NOEXCEPT {}
784 _LIBCPP_INLINE_VISIBILITY
785 __map_const_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
786 _LIBCPP_INLINE_VISIBILITY
787 __map_const_iterator(__map_iterator<
788 typename _TreeIterator::__non_const_iterator> __i) _NOEXCEPT
791 _LIBCPP_INLINE_VISIBILITY
792 reference operator*() const {return __i_->__cc;}
793 _LIBCPP_INLINE_VISIBILITY
794 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
796 _LIBCPP_INLINE_VISIBILITY
797 __map_const_iterator& operator++() {++__i_; return *this;}
798 _LIBCPP_INLINE_VISIBILITY
799 __map_const_iterator operator++(int)
801 __map_const_iterator __t(*this);
806 _LIBCPP_INLINE_VISIBILITY
807 __map_const_iterator& operator--() {--__i_; return *this;}
808 _LIBCPP_INLINE_VISIBILITY
809 __map_const_iterator operator--(int)
811 __map_const_iterator __t(*this);
816 friend _LIBCPP_INLINE_VISIBILITY
817 bool operator==(const __map_const_iterator& __x, const __map_const_iterator& __y)
818 {return __x.__i_ == __y.__i_;}
819 friend _LIBCPP_INLINE_VISIBILITY
820 bool operator!=(const __map_const_iterator& __x, const __map_const_iterator& __y)
821 {return __x.__i_ != __y.__i_;}
823 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY map;
824 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY multimap;
825 template <class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY __tree_const_iterator;
828 template <class _Key, class _Tp, class _Compare = less<_Key>,
829 class _Allocator = allocator<pair<const _Key, _Tp> > >
830 class _LIBCPP_TYPE_VIS_ONLY map
834 typedef _Key key_type;
835 typedef _Tp mapped_type;
836 typedef pair<const key_type, mapped_type> value_type;
837 typedef pair<key_type, mapped_type> __nc_value_type;
838 typedef _Compare key_compare;
839 typedef _Allocator allocator_type;
840 typedef value_type& reference;
841 typedef const value_type& const_reference;
843 class _LIBCPP_TYPE_VIS_ONLY value_compare
844 : public binary_function<value_type, value_type, bool>
850 _LIBCPP_INLINE_VISIBILITY value_compare(key_compare c) : comp(c) {}
852 _LIBCPP_INLINE_VISIBILITY
853 bool operator()(const value_type& __x, const value_type& __y) const
854 {return comp(__x.first, __y.first);}
859 typedef _VSTD::__value_type<key_type, mapped_type> __value_type;
860 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
861 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
862 __value_type>::type __allocator_type;
863 typedef __tree<__value_type, __vc, __allocator_type> __base;
864 typedef typename __base::__node_traits __node_traits;
865 typedef allocator_traits<allocator_type> __alloc_traits;
870 typedef typename __alloc_traits::pointer pointer;
871 typedef typename __alloc_traits::const_pointer const_pointer;
872 typedef typename __alloc_traits::size_type size_type;
873 typedef typename __alloc_traits::difference_type difference_type;
874 typedef __map_iterator<typename __base::iterator> iterator;
875 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
876 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
877 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
879 _LIBCPP_INLINE_VISIBILITY
882 is_nothrow_default_constructible<allocator_type>::value &&
883 is_nothrow_default_constructible<key_compare>::value &&
884 is_nothrow_copy_constructible<key_compare>::value)
885 : __tree_(__vc(key_compare())) {}
887 _LIBCPP_INLINE_VISIBILITY
888 explicit map(const key_compare& __comp)
890 is_nothrow_default_constructible<allocator_type>::value &&
891 is_nothrow_copy_constructible<key_compare>::value)
892 : __tree_(__vc(__comp)) {}
894 _LIBCPP_INLINE_VISIBILITY
895 explicit map(const key_compare& __comp, const allocator_type& __a)
896 : __tree_(__vc(__comp), __a) {}
898 template <class _InputIterator>
899 _LIBCPP_INLINE_VISIBILITY
900 map(_InputIterator __f, _InputIterator __l,
901 const key_compare& __comp = key_compare())
902 : __tree_(__vc(__comp))
907 template <class _InputIterator>
908 _LIBCPP_INLINE_VISIBILITY
909 map(_InputIterator __f, _InputIterator __l,
910 const key_compare& __comp, const allocator_type& __a)
911 : __tree_(__vc(__comp), __a)
916 #if _LIBCPP_STD_VER > 11
917 template <class _InputIterator>
918 _LIBCPP_INLINE_VISIBILITY
919 map(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
920 : map(__f, __l, key_compare(), __a) {}
923 _LIBCPP_INLINE_VISIBILITY
925 : __tree_(__m.__tree_)
927 insert(__m.begin(), __m.end());
930 _LIBCPP_INLINE_VISIBILITY
931 map& operator=(const map& __m)
933 #if __cplusplus >= 201103L
934 __tree_ = __m.__tree_;
938 __tree_.value_comp() = __m.__tree_.value_comp();
939 __tree_.__copy_assign_alloc(__m.__tree_);
940 insert(__m.begin(), __m.end());
946 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
948 _LIBCPP_INLINE_VISIBILITY
950 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
951 : __tree_(_VSTD::move(__m.__tree_))
955 map(map&& __m, const allocator_type& __a);
957 _LIBCPP_INLINE_VISIBILITY
958 map& operator=(map&& __m)
959 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
961 __tree_ = _VSTD::move(__m.__tree_);
965 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
967 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
969 _LIBCPP_INLINE_VISIBILITY
970 map(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
971 : __tree_(__vc(__comp))
973 insert(__il.begin(), __il.end());
976 _LIBCPP_INLINE_VISIBILITY
977 map(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
978 : __tree_(__vc(__comp), __a)
980 insert(__il.begin(), __il.end());
983 #if _LIBCPP_STD_VER > 11
984 _LIBCPP_INLINE_VISIBILITY
985 map(initializer_list<value_type> __il, const allocator_type& __a)
986 : map(__il, key_compare(), __a) {}
989 _LIBCPP_INLINE_VISIBILITY
990 map& operator=(initializer_list<value_type> __il)
992 __tree_.__assign_unique(__il.begin(), __il.end());
996 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
998 _LIBCPP_INLINE_VISIBILITY
999 explicit map(const allocator_type& __a)
1004 _LIBCPP_INLINE_VISIBILITY
1005 map(const map& __m, const allocator_type& __a)
1006 : __tree_(__m.__tree_.value_comp(), __a)
1008 insert(__m.begin(), __m.end());
1011 _LIBCPP_INLINE_VISIBILITY
1012 iterator begin() _NOEXCEPT {return __tree_.begin();}
1013 _LIBCPP_INLINE_VISIBILITY
1014 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
1015 _LIBCPP_INLINE_VISIBILITY
1016 iterator end() _NOEXCEPT {return __tree_.end();}
1017 _LIBCPP_INLINE_VISIBILITY
1018 const_iterator end() const _NOEXCEPT {return __tree_.end();}
1020 _LIBCPP_INLINE_VISIBILITY
1021 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
1022 _LIBCPP_INLINE_VISIBILITY
1023 const_reverse_iterator rbegin() const _NOEXCEPT
1024 {return const_reverse_iterator(end());}
1025 _LIBCPP_INLINE_VISIBILITY
1026 reverse_iterator rend() _NOEXCEPT
1027 {return reverse_iterator(begin());}
1028 _LIBCPP_INLINE_VISIBILITY
1029 const_reverse_iterator rend() const _NOEXCEPT
1030 {return const_reverse_iterator(begin());}
1032 _LIBCPP_INLINE_VISIBILITY
1033 const_iterator cbegin() const _NOEXCEPT {return begin();}
1034 _LIBCPP_INLINE_VISIBILITY
1035 const_iterator cend() const _NOEXCEPT {return end();}
1036 _LIBCPP_INLINE_VISIBILITY
1037 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
1038 _LIBCPP_INLINE_VISIBILITY
1039 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
1041 _LIBCPP_INLINE_VISIBILITY
1042 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
1043 _LIBCPP_INLINE_VISIBILITY
1044 size_type size() const _NOEXCEPT {return __tree_.size();}
1045 _LIBCPP_INLINE_VISIBILITY
1046 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
1048 mapped_type& operator[](const key_type& __k);
1049 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1050 mapped_type& operator[](key_type&& __k);
1053 mapped_type& at(const key_type& __k);
1054 const mapped_type& at(const key_type& __k) const;
1056 _LIBCPP_INLINE_VISIBILITY
1057 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
1058 _LIBCPP_INLINE_VISIBILITY
1059 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
1060 _LIBCPP_INLINE_VISIBILITY
1061 value_compare value_comp() const {return value_compare(__tree_.value_comp().key_comp());}
1063 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1064 #ifndef _LIBCPP_HAS_NO_VARIADICS
1066 template <class ..._Args>
1067 pair<iterator, bool>
1068 emplace(_Args&& ...__args);
1070 template <class ..._Args>
1072 emplace_hint(const_iterator __p, _Args&& ...__args);
1074 #endif // _LIBCPP_HAS_NO_VARIADICS
1076 template <class _Pp,
1077 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
1078 _LIBCPP_INLINE_VISIBILITY
1079 pair<iterator, bool> insert(_Pp&& __p)
1080 {return __tree_.__insert_unique(_VSTD::forward<_Pp>(__p));}
1082 template <class _Pp,
1083 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
1084 _LIBCPP_INLINE_VISIBILITY
1085 iterator insert(const_iterator __pos, _Pp&& __p)
1086 {return __tree_.__insert_unique(__pos.__i_, _VSTD::forward<_Pp>(__p));}
1088 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1090 _LIBCPP_INLINE_VISIBILITY
1091 pair<iterator, bool>
1092 insert(const value_type& __v) {return __tree_.__insert_unique(__v);}
1094 _LIBCPP_INLINE_VISIBILITY
1096 insert(const_iterator __p, const value_type& __v)
1097 {return __tree_.__insert_unique(__p.__i_, __v);}
1099 template <class _InputIterator>
1100 _LIBCPP_INLINE_VISIBILITY
1101 void insert(_InputIterator __f, _InputIterator __l)
1103 for (const_iterator __e = cend(); __f != __l; ++__f)
1104 insert(__e.__i_, *__f);
1107 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1109 _LIBCPP_INLINE_VISIBILITY
1110 void insert(initializer_list<value_type> __il)
1111 {insert(__il.begin(), __il.end());}
1113 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1115 #if _LIBCPP_STD_VER > 14
1116 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1117 #ifndef _LIBCPP_HAS_NO_VARIADICS
1118 template <class... _Args>
1119 _LIBCPP_INLINE_VISIBILITY
1120 pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args)
1122 iterator __p = lower_bound(__k);
1123 if ( __p != end() && !key_comp()(__k, __p->first))
1124 return _VSTD::make_pair(__p, false);
1126 return _VSTD::make_pair(
1128 _VSTD::piecewise_construct, _VSTD::forward_as_tuple(__k),
1129 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)),
1133 template <class... _Args>
1134 _LIBCPP_INLINE_VISIBILITY
1135 pair<iterator, bool> try_emplace(key_type&& __k, _Args&&... __args)
1137 iterator __p = lower_bound(__k);
1138 if ( __p != end() && !key_comp()(__k, __p->first))
1139 return _VSTD::make_pair(__p, false);
1141 return _VSTD::make_pair(
1143 _VSTD::piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__k)),
1144 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)),
1148 template <class... _Args>
1149 _LIBCPP_INLINE_VISIBILITY
1150 iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args)
1152 iterator __p = lower_bound(__k);
1153 if ( __p != end() && !key_comp()(__k, __p->first))
1156 return emplace_hint(__p,
1157 _VSTD::piecewise_construct, _VSTD::forward_as_tuple(__k),
1158 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
1161 template <class... _Args>
1162 _LIBCPP_INLINE_VISIBILITY
1163 iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args)
1165 iterator __p = lower_bound(__k);
1166 if ( __p != end() && !key_comp()(__k, __p->first))
1169 return emplace_hint(__p,
1170 _VSTD::piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__k)),
1171 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
1174 template <class _Vp>
1175 _LIBCPP_INLINE_VISIBILITY
1176 pair<iterator, bool> insert_or_assign(const key_type& __k, _Vp&& __v)
1178 iterator __p = lower_bound(__k);
1179 if ( __p != end() && !key_comp()(__k, __p->first))
1181 __p->second = _VSTD::forward<_Vp>(__v);
1182 return _VSTD::make_pair(__p, false);
1184 return _VSTD::make_pair(emplace_hint(__p, __k, _VSTD::forward<_Vp>(__v)), true);
1187 template <class _Vp>
1188 _LIBCPP_INLINE_VISIBILITY
1189 pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v)
1191 iterator __p = lower_bound(__k);
1192 if ( __p != end() && !key_comp()(__k, __p->first))
1194 __p->second = _VSTD::forward<_Vp>(__v);
1195 return _VSTD::make_pair(__p, false);
1197 return _VSTD::make_pair(emplace_hint(__p, _VSTD::move(__k), _VSTD::forward<_Vp>(__v)), true);
1200 template <class _Vp>
1201 _LIBCPP_INLINE_VISIBILITY
1202 iterator insert_or_assign(const_iterator __h, const key_type& __k, _Vp&& __v)
1204 iterator __p = lower_bound(__k);
1205 if ( __p != end() && !key_comp()(__k, __p->first))
1207 __p->second = _VSTD::forward<_Vp>(__v);
1210 return emplace_hint(__h, __k, _VSTD::forward<_Vp>(__v));
1213 template <class _Vp>
1214 _LIBCPP_INLINE_VISIBILITY
1215 iterator insert_or_assign(const_iterator __h, key_type&& __k, _Vp&& __v)
1217 iterator __p = lower_bound(__k);
1218 if ( __p != end() && !key_comp()(__k, __p->first))
1220 __p->second = _VSTD::forward<_Vp>(__v);
1223 return emplace_hint(__h, _VSTD::move(__k), _VSTD::forward<_Vp>(__v));
1229 _LIBCPP_INLINE_VISIBILITY
1230 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
1231 _LIBCPP_INLINE_VISIBILITY
1232 iterator erase(iterator __p) {return __tree_.erase(__p.__i_);}
1233 _LIBCPP_INLINE_VISIBILITY
1234 size_type erase(const key_type& __k)
1235 {return __tree_.__erase_unique(__k);}
1236 _LIBCPP_INLINE_VISIBILITY
1237 iterator erase(const_iterator __f, const_iterator __l)
1238 {return __tree_.erase(__f.__i_, __l.__i_);}
1239 _LIBCPP_INLINE_VISIBILITY
1240 void clear() _NOEXCEPT {__tree_.clear();}
1242 _LIBCPP_INLINE_VISIBILITY
1244 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1245 {__tree_.swap(__m.__tree_);}
1247 _LIBCPP_INLINE_VISIBILITY
1248 iterator find(const key_type& __k) {return __tree_.find(__k);}
1249 _LIBCPP_INLINE_VISIBILITY
1250 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
1251 #if _LIBCPP_STD_VER > 11
1252 template <typename _K2>
1253 _LIBCPP_INLINE_VISIBILITY
1254 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1255 find(const _K2& __k) {return __tree_.find(__k);}
1256 template <typename _K2>
1257 _LIBCPP_INLINE_VISIBILITY
1258 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1259 find(const _K2& __k) const {return __tree_.find(__k);}
1262 _LIBCPP_INLINE_VISIBILITY
1263 size_type count(const key_type& __k) const
1264 {return __tree_.__count_unique(__k);}
1265 #if _LIBCPP_STD_VER > 11
1266 template <typename _K2>
1267 _LIBCPP_INLINE_VISIBILITY
1268 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
1269 count(const _K2& __k) const {return __tree_.__count_unique(__k);}
1271 _LIBCPP_INLINE_VISIBILITY
1272 iterator lower_bound(const key_type& __k)
1273 {return __tree_.lower_bound(__k);}
1274 _LIBCPP_INLINE_VISIBILITY
1275 const_iterator lower_bound(const key_type& __k) const
1276 {return __tree_.lower_bound(__k);}
1277 #if _LIBCPP_STD_VER > 11
1278 template <typename _K2>
1279 _LIBCPP_INLINE_VISIBILITY
1280 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1281 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
1283 template <typename _K2>
1284 _LIBCPP_INLINE_VISIBILITY
1285 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1286 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
1289 _LIBCPP_INLINE_VISIBILITY
1290 iterator upper_bound(const key_type& __k)
1291 {return __tree_.upper_bound(__k);}
1292 _LIBCPP_INLINE_VISIBILITY
1293 const_iterator upper_bound(const key_type& __k) const
1294 {return __tree_.upper_bound(__k);}
1295 #if _LIBCPP_STD_VER > 11
1296 template <typename _K2>
1297 _LIBCPP_INLINE_VISIBILITY
1298 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1299 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
1300 template <typename _K2>
1301 _LIBCPP_INLINE_VISIBILITY
1302 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1303 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
1306 _LIBCPP_INLINE_VISIBILITY
1307 pair<iterator,iterator> equal_range(const key_type& __k)
1308 {return __tree_.__equal_range_unique(__k);}
1309 _LIBCPP_INLINE_VISIBILITY
1310 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
1311 {return __tree_.__equal_range_unique(__k);}
1312 #if _LIBCPP_STD_VER > 11
1313 template <typename _K2>
1314 _LIBCPP_INLINE_VISIBILITY
1315 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
1316 equal_range(const _K2& __k) {return __tree_.__equal_range_unique(__k);}
1317 template <typename _K2>
1318 _LIBCPP_INLINE_VISIBILITY
1319 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
1320 equal_range(const _K2& __k) const {return __tree_.__equal_range_unique(__k);}
1324 typedef typename __base::__node __node;
1325 typedef typename __base::__node_allocator __node_allocator;
1326 typedef typename __base::__node_pointer __node_pointer;
1327 typedef typename __base::__node_const_pointer __node_const_pointer;
1328 typedef typename __base::__node_base_pointer __node_base_pointer;
1329 typedef typename __base::__node_base_const_pointer __node_base_const_pointer;
1330 typedef __map_node_destructor<__node_allocator> _Dp;
1331 typedef unique_ptr<__node, _Dp> __node_holder;
1333 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1334 __node_holder __construct_node();
1335 template <class _A0>
1336 __node_holder __construct_node(_A0&& __a0);
1337 __node_holder __construct_node_with_key(key_type&& __k);
1338 #ifndef _LIBCPP_HAS_NO_VARIADICS
1339 template <class _A0, class _A1, class ..._Args>
1340 __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
1341 #endif // _LIBCPP_HAS_NO_VARIADICS
1343 __node_holder __construct_node_with_key(const key_type& __k);
1345 __node_base_pointer&
1346 __find_equal_key(__node_base_pointer& __parent, const key_type& __k);
1347 __node_base_const_pointer
1348 __find_equal_key(__node_base_const_pointer& __parent, const key_type& __k) const;
1351 // Find place to insert if __k doesn't exist
1352 // Set __parent to parent of null leaf
1353 // Return reference to null leaf
1354 // If __k exists, set parent to node of __k and return reference to node of __k
1355 template <class _Key, class _Tp, class _Compare, class _Allocator>
1356 typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_pointer&
1357 map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(__node_base_pointer& __parent,
1358 const key_type& __k)
1360 __node_pointer __nd = __tree_.__root();
1361 if (__nd != nullptr)
1365 if (__tree_.value_comp().key_comp()(__k, __nd->__value_.__cc.first))
1367 if (__nd->__left_ != nullptr)
1368 __nd = static_cast<__node_pointer>(__nd->__left_);
1371 __parent = static_cast<__node_base_pointer>(__nd);
1372 return __parent->__left_;
1375 else if (__tree_.value_comp().key_comp()(__nd->__value_.__cc.first, __k))
1377 if (__nd->__right_ != nullptr)
1378 __nd = static_cast<__node_pointer>(__nd->__right_);
1381 __parent = static_cast<__node_base_pointer>(__nd);
1382 return __parent->__right_;
1387 __parent = static_cast<__node_base_pointer>(__nd);
1392 __parent = static_cast<__node_base_pointer>(__tree_.__end_node());
1393 return __parent->__left_;
1397 // Set __parent to parent of null leaf and
1398 // return reference to null leaf iv __k does not exist.
1399 // If __k exists, set parent to node of __k and return reference to node of __k
1400 template <class _Key, class _Tp, class _Compare, class _Allocator>
1401 typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_const_pointer
1402 map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(__node_base_const_pointer& __parent,
1403 const key_type& __k) const
1405 __node_const_pointer __nd = __tree_.__root();
1406 if (__nd != nullptr)
1410 if (__tree_.value_comp().key_comp()(__k, __nd->__value_.__cc.first))
1412 if (__nd->__left_ != nullptr)
1413 __nd = static_cast<__node_pointer>(__nd->__left_);
1416 __parent = static_cast<__node_base_pointer>(__nd);
1417 return const_cast<const __node_base_const_pointer&>(__parent->__left_);
1420 else if (__tree_.value_comp().key_comp()(__nd->__value_.__cc.first, __k))
1422 if (__nd->__right_ != nullptr)
1423 __nd = static_cast<__node_pointer>(__nd->__right_);
1426 __parent = static_cast<__node_base_pointer>(__nd);
1427 return const_cast<const __node_base_const_pointer&>(__parent->__right_);
1432 __parent = static_cast<__node_base_pointer>(__nd);
1437 __parent = static_cast<__node_base_pointer>(__tree_.__end_node());
1438 return const_cast<const __node_base_const_pointer&>(__parent->__left_);
1441 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1443 template <class _Key, class _Tp, class _Compare, class _Allocator>
1444 map<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a)
1445 : __tree_(_VSTD::move(__m.__tree_), __a)
1447 if (__a != __m.get_allocator())
1449 const_iterator __e = cend();
1450 while (!__m.empty())
1451 __tree_.__insert_unique(__e.__i_,
1452 _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_));
1456 template <class _Key, class _Tp, class _Compare, class _Allocator>
1457 typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1458 map<_Key, _Tp, _Compare, _Allocator>::__construct_node()
1460 __node_allocator& __na = __tree_.__node_alloc();
1461 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1462 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first));
1463 __h.get_deleter().__first_constructed = true;
1464 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
1465 __h.get_deleter().__second_constructed = true;
1469 template <class _Key, class _Tp, class _Compare, class _Allocator>
1470 template <class _A0>
1471 typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1472 map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0)
1474 __node_allocator& __na = __tree_.__node_alloc();
1475 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1476 __node_traits::construct(__na, _VSTD::addressof(__h->__value_), _VSTD::forward<_A0>(__a0));
1477 __h.get_deleter().__first_constructed = true;
1478 __h.get_deleter().__second_constructed = true;
1482 template <class _Key, class _Tp, class _Compare, class _Allocator>
1483 typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1484 map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(key_type&& __k)
1486 __node_allocator& __na = __tree_.__node_alloc();
1487 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1488 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), _VSTD::move(__k));
1489 __h.get_deleter().__first_constructed = true;
1490 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
1491 __h.get_deleter().__second_constructed = true;
1495 #ifndef _LIBCPP_HAS_NO_VARIADICS
1497 template <class _Key, class _Tp, class _Compare, class _Allocator>
1498 template <class _A0, class _A1, class ..._Args>
1499 typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1500 map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args)
1502 __node_allocator& __na = __tree_.__node_alloc();
1503 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1504 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
1505 _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
1506 _VSTD::forward<_Args>(__args)...);
1507 __h.get_deleter().__first_constructed = true;
1508 __h.get_deleter().__second_constructed = true;
1512 #endif // _LIBCPP_HAS_NO_VARIADICS
1514 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1516 template <class _Key, class _Tp, class _Compare, class _Allocator>
1517 typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1518 map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(const key_type& __k)
1520 __node_allocator& __na = __tree_.__node_alloc();
1521 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1522 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), __k);
1523 __h.get_deleter().__first_constructed = true;
1524 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
1525 __h.get_deleter().__second_constructed = true;
1526 return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03
1529 template <class _Key, class _Tp, class _Compare, class _Allocator>
1531 map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k)
1533 __node_base_pointer __parent;
1534 __node_base_pointer& __child = __find_equal_key(__parent, __k);
1535 __node_pointer __r = static_cast<__node_pointer>(__child);
1536 if (__child == nullptr)
1538 __node_holder __h = __construct_node_with_key(__k);
1539 __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
1540 __r = __h.release();
1542 return __r->__value_.__cc.second;
1545 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1547 template <class _Key, class _Tp, class _Compare, class _Allocator>
1549 map<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k)
1551 __node_base_pointer __parent;
1552 __node_base_pointer& __child = __find_equal_key(__parent, __k);
1553 __node_pointer __r = static_cast<__node_pointer>(__child);
1554 if (__child == nullptr)
1556 __node_holder __h = __construct_node_with_key(_VSTD::move(__k));
1557 __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
1558 __r = __h.release();
1560 return __r->__value_.__cc.second;
1563 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1565 template <class _Key, class _Tp, class _Compare, class _Allocator>
1567 map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k)
1569 __node_base_pointer __parent;
1570 __node_base_pointer& __child = __find_equal_key(__parent, __k);
1571 #ifndef _LIBCPP_NO_EXCEPTIONS
1572 if (__child == nullptr)
1573 throw out_of_range("map::at: key not found");
1574 #endif // _LIBCPP_NO_EXCEPTIONS
1575 return static_cast<__node_pointer>(__child)->__value_.__cc.second;
1578 template <class _Key, class _Tp, class _Compare, class _Allocator>
1580 map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const
1582 __node_base_const_pointer __parent;
1583 __node_base_const_pointer __child = __find_equal_key(__parent, __k);
1584 #ifndef _LIBCPP_NO_EXCEPTIONS
1585 if (__child == nullptr)
1586 throw out_of_range("map::at: key not found");
1587 #endif // _LIBCPP_NO_EXCEPTIONS
1588 return static_cast<__node_const_pointer>(__child)->__value_.__cc.second;
1591 #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1593 template <class _Key, class _Tp, class _Compare, class _Allocator>
1594 template <class ..._Args>
1595 pair<typename map<_Key, _Tp, _Compare, _Allocator>::iterator, bool>
1596 map<_Key, _Tp, _Compare, _Allocator>::emplace(_Args&& ...__args)
1598 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
1599 pair<iterator, bool> __r = __tree_.__node_insert_unique(__h.get());
1605 template <class _Key, class _Tp, class _Compare, class _Allocator>
1606 template <class ..._Args>
1607 typename map<_Key, _Tp, _Compare, _Allocator>::iterator
1608 map<_Key, _Tp, _Compare, _Allocator>::emplace_hint(const_iterator __p,
1611 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
1612 iterator __r = __tree_.__node_insert_unique(__p.__i_, __h.get());
1613 if (__r.__i_.__ptr_ == __h.get())
1618 #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1620 template <class _Key, class _Tp, class _Compare, class _Allocator>
1621 inline _LIBCPP_INLINE_VISIBILITY
1623 operator==(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1624 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1626 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
1629 template <class _Key, class _Tp, class _Compare, class _Allocator>
1630 inline _LIBCPP_INLINE_VISIBILITY
1632 operator< (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1633 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1635 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
1638 template <class _Key, class _Tp, class _Compare, class _Allocator>
1639 inline _LIBCPP_INLINE_VISIBILITY
1641 operator!=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1642 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1644 return !(__x == __y);
1647 template <class _Key, class _Tp, class _Compare, class _Allocator>
1648 inline _LIBCPP_INLINE_VISIBILITY
1650 operator> (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1651 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1656 template <class _Key, class _Tp, class _Compare, class _Allocator>
1657 inline _LIBCPP_INLINE_VISIBILITY
1659 operator>=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1660 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1662 return !(__x < __y);
1665 template <class _Key, class _Tp, class _Compare, class _Allocator>
1666 inline _LIBCPP_INLINE_VISIBILITY
1668 operator<=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1669 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1671 return !(__y < __x);
1674 template <class _Key, class _Tp, class _Compare, class _Allocator>
1675 inline _LIBCPP_INLINE_VISIBILITY
1677 swap(map<_Key, _Tp, _Compare, _Allocator>& __x,
1678 map<_Key, _Tp, _Compare, _Allocator>& __y)
1679 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
1684 template <class _Key, class _Tp, class _Compare = less<_Key>,
1685 class _Allocator = allocator<pair<const _Key, _Tp> > >
1686 class _LIBCPP_TYPE_VIS_ONLY multimap
1690 typedef _Key key_type;
1691 typedef _Tp mapped_type;
1692 typedef pair<const key_type, mapped_type> value_type;
1693 typedef pair<key_type, mapped_type> __nc_value_type;
1694 typedef _Compare key_compare;
1695 typedef _Allocator allocator_type;
1696 typedef value_type& reference;
1697 typedef const value_type& const_reference;
1699 class _LIBCPP_TYPE_VIS_ONLY value_compare
1700 : public binary_function<value_type, value_type, bool>
1702 friend class multimap;
1706 _LIBCPP_INLINE_VISIBILITY
1707 value_compare(key_compare c) : comp(c) {}
1709 _LIBCPP_INLINE_VISIBILITY
1710 bool operator()(const value_type& __x, const value_type& __y) const
1711 {return comp(__x.first, __y.first);}
1716 typedef _VSTD::__value_type<key_type, mapped_type> __value_type;
1717 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
1718 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
1719 __value_type>::type __allocator_type;
1720 typedef __tree<__value_type, __vc, __allocator_type> __base;
1721 typedef typename __base::__node_traits __node_traits;
1722 typedef allocator_traits<allocator_type> __alloc_traits;
1727 typedef typename __alloc_traits::pointer pointer;
1728 typedef typename __alloc_traits::const_pointer const_pointer;
1729 typedef typename __alloc_traits::size_type size_type;
1730 typedef typename __alloc_traits::difference_type difference_type;
1731 typedef __map_iterator<typename __base::iterator> iterator;
1732 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
1733 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1734 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
1736 _LIBCPP_INLINE_VISIBILITY
1739 is_nothrow_default_constructible<allocator_type>::value &&
1740 is_nothrow_default_constructible<key_compare>::value &&
1741 is_nothrow_copy_constructible<key_compare>::value)
1742 : __tree_(__vc(key_compare())) {}
1744 _LIBCPP_INLINE_VISIBILITY
1745 explicit multimap(const key_compare& __comp)
1747 is_nothrow_default_constructible<allocator_type>::value &&
1748 is_nothrow_copy_constructible<key_compare>::value)
1749 : __tree_(__vc(__comp)) {}
1751 _LIBCPP_INLINE_VISIBILITY
1752 explicit multimap(const key_compare& __comp, const allocator_type& __a)
1753 : __tree_(__vc(__comp), __a) {}
1755 template <class _InputIterator>
1756 _LIBCPP_INLINE_VISIBILITY
1757 multimap(_InputIterator __f, _InputIterator __l,
1758 const key_compare& __comp = key_compare())
1759 : __tree_(__vc(__comp))
1764 template <class _InputIterator>
1765 _LIBCPP_INLINE_VISIBILITY
1766 multimap(_InputIterator __f, _InputIterator __l,
1767 const key_compare& __comp, const allocator_type& __a)
1768 : __tree_(__vc(__comp), __a)
1773 #if _LIBCPP_STD_VER > 11
1774 template <class _InputIterator>
1775 _LIBCPP_INLINE_VISIBILITY
1776 multimap(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
1777 : multimap(__f, __l, key_compare(), __a) {}
1780 _LIBCPP_INLINE_VISIBILITY
1781 multimap(const multimap& __m)
1782 : __tree_(__m.__tree_.value_comp(),
1783 __alloc_traits::select_on_container_copy_construction(__m.__tree_.__alloc()))
1785 insert(__m.begin(), __m.end());
1788 _LIBCPP_INLINE_VISIBILITY
1789 multimap& operator=(const multimap& __m)
1791 #if __cplusplus >= 201103L
1792 __tree_ = __m.__tree_;
1796 __tree_.value_comp() = __m.__tree_.value_comp();
1797 __tree_.__copy_assign_alloc(__m.__tree_);
1798 insert(__m.begin(), __m.end());
1804 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1806 _LIBCPP_INLINE_VISIBILITY
1807 multimap(multimap&& __m)
1808 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
1809 : __tree_(_VSTD::move(__m.__tree_))
1813 multimap(multimap&& __m, const allocator_type& __a);
1815 _LIBCPP_INLINE_VISIBILITY
1816 multimap& operator=(multimap&& __m)
1817 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
1819 __tree_ = _VSTD::move(__m.__tree_);
1823 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1825 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1827 _LIBCPP_INLINE_VISIBILITY
1828 multimap(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
1829 : __tree_(__vc(__comp))
1831 insert(__il.begin(), __il.end());
1834 _LIBCPP_INLINE_VISIBILITY
1835 multimap(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
1836 : __tree_(__vc(__comp), __a)
1838 insert(__il.begin(), __il.end());
1841 #if _LIBCPP_STD_VER > 11
1842 _LIBCPP_INLINE_VISIBILITY
1843 multimap(initializer_list<value_type> __il, const allocator_type& __a)
1844 : multimap(__il, key_compare(), __a) {}
1847 _LIBCPP_INLINE_VISIBILITY
1848 multimap& operator=(initializer_list<value_type> __il)
1850 __tree_.__assign_multi(__il.begin(), __il.end());
1854 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1856 _LIBCPP_INLINE_VISIBILITY
1857 explicit multimap(const allocator_type& __a)
1862 _LIBCPP_INLINE_VISIBILITY
1863 multimap(const multimap& __m, const allocator_type& __a)
1864 : __tree_(__m.__tree_.value_comp(), __a)
1866 insert(__m.begin(), __m.end());
1869 _LIBCPP_INLINE_VISIBILITY
1870 iterator begin() _NOEXCEPT {return __tree_.begin();}
1871 _LIBCPP_INLINE_VISIBILITY
1872 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
1873 _LIBCPP_INLINE_VISIBILITY
1874 iterator end() _NOEXCEPT {return __tree_.end();}
1875 _LIBCPP_INLINE_VISIBILITY
1876 const_iterator end() const _NOEXCEPT {return __tree_.end();}
1878 _LIBCPP_INLINE_VISIBILITY
1879 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
1880 _LIBCPP_INLINE_VISIBILITY
1881 const_reverse_iterator rbegin() const _NOEXCEPT
1882 {return const_reverse_iterator(end());}
1883 _LIBCPP_INLINE_VISIBILITY
1884 reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
1885 _LIBCPP_INLINE_VISIBILITY
1886 const_reverse_iterator rend() const _NOEXCEPT
1887 {return const_reverse_iterator(begin());}
1889 _LIBCPP_INLINE_VISIBILITY
1890 const_iterator cbegin() const _NOEXCEPT {return begin();}
1891 _LIBCPP_INLINE_VISIBILITY
1892 const_iterator cend() const _NOEXCEPT {return end();}
1893 _LIBCPP_INLINE_VISIBILITY
1894 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
1895 _LIBCPP_INLINE_VISIBILITY
1896 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
1898 _LIBCPP_INLINE_VISIBILITY
1899 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
1900 _LIBCPP_INLINE_VISIBILITY
1901 size_type size() const _NOEXCEPT {return __tree_.size();}
1902 _LIBCPP_INLINE_VISIBILITY
1903 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
1905 _LIBCPP_INLINE_VISIBILITY
1906 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
1907 _LIBCPP_INLINE_VISIBILITY
1908 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
1909 _LIBCPP_INLINE_VISIBILITY
1910 value_compare value_comp() const
1911 {return value_compare(__tree_.value_comp().key_comp());}
1913 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1914 #ifndef _LIBCPP_HAS_NO_VARIADICS
1916 template <class ..._Args>
1918 emplace(_Args&& ...__args);
1920 template <class ..._Args>
1922 emplace_hint(const_iterator __p, _Args&& ...__args);
1924 #endif // _LIBCPP_HAS_NO_VARIADICS
1926 template <class _Pp,
1927 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
1928 _LIBCPP_INLINE_VISIBILITY
1929 iterator insert(_Pp&& __p)
1930 {return __tree_.__insert_multi(_VSTD::forward<_Pp>(__p));}
1932 template <class _Pp,
1933 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
1934 _LIBCPP_INLINE_VISIBILITY
1935 iterator insert(const_iterator __pos, _Pp&& __p)
1936 {return __tree_.__insert_multi(__pos.__i_, _VSTD::forward<_Pp>(__p));}
1938 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1940 _LIBCPP_INLINE_VISIBILITY
1941 iterator insert(const value_type& __v) {return __tree_.__insert_multi(__v);}
1943 _LIBCPP_INLINE_VISIBILITY
1944 iterator insert(const_iterator __p, const value_type& __v)
1945 {return __tree_.__insert_multi(__p.__i_, __v);}
1947 template <class _InputIterator>
1948 _LIBCPP_INLINE_VISIBILITY
1949 void insert(_InputIterator __f, _InputIterator __l)
1951 for (const_iterator __e = cend(); __f != __l; ++__f)
1952 __tree_.__insert_multi(__e.__i_, *__f);
1955 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1957 _LIBCPP_INLINE_VISIBILITY
1958 void insert(initializer_list<value_type> __il)
1959 {insert(__il.begin(), __il.end());}
1961 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1963 _LIBCPP_INLINE_VISIBILITY
1964 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
1965 _LIBCPP_INLINE_VISIBILITY
1966 iterator erase(iterator __p) {return __tree_.erase(__p.__i_);}
1967 _LIBCPP_INLINE_VISIBILITY
1968 size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
1969 _LIBCPP_INLINE_VISIBILITY
1970 iterator erase(const_iterator __f, const_iterator __l)
1971 {return __tree_.erase(__f.__i_, __l.__i_);}
1972 _LIBCPP_INLINE_VISIBILITY
1973 void clear() {__tree_.clear();}
1975 _LIBCPP_INLINE_VISIBILITY
1976 void swap(multimap& __m)
1977 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1978 {__tree_.swap(__m.__tree_);}
1980 _LIBCPP_INLINE_VISIBILITY
1981 iterator find(const key_type& __k) {return __tree_.find(__k);}
1982 _LIBCPP_INLINE_VISIBILITY
1983 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
1984 #if _LIBCPP_STD_VER > 11
1985 template <typename _K2>
1986 _LIBCPP_INLINE_VISIBILITY
1987 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1988 find(const _K2& __k) {return __tree_.find(__k);}
1989 template <typename _K2>
1990 _LIBCPP_INLINE_VISIBILITY
1991 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1992 find(const _K2& __k) const {return __tree_.find(__k);}
1995 _LIBCPP_INLINE_VISIBILITY
1996 size_type count(const key_type& __k) const
1997 {return __tree_.__count_multi(__k);}
1998 #if _LIBCPP_STD_VER > 11
1999 template <typename _K2>
2000 _LIBCPP_INLINE_VISIBILITY
2001 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
2002 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
2004 _LIBCPP_INLINE_VISIBILITY
2005 iterator lower_bound(const key_type& __k)
2006 {return __tree_.lower_bound(__k);}
2007 _LIBCPP_INLINE_VISIBILITY
2008 const_iterator lower_bound(const key_type& __k) const
2009 {return __tree_.lower_bound(__k);}
2010 #if _LIBCPP_STD_VER > 11
2011 template <typename _K2>
2012 _LIBCPP_INLINE_VISIBILITY
2013 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
2014 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
2016 template <typename _K2>
2017 _LIBCPP_INLINE_VISIBILITY
2018 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
2019 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
2022 _LIBCPP_INLINE_VISIBILITY
2023 iterator upper_bound(const key_type& __k)
2024 {return __tree_.upper_bound(__k);}
2025 _LIBCPP_INLINE_VISIBILITY
2026 const_iterator upper_bound(const key_type& __k) const
2027 {return __tree_.upper_bound(__k);}
2028 #if _LIBCPP_STD_VER > 11
2029 template <typename _K2>
2030 _LIBCPP_INLINE_VISIBILITY
2031 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
2032 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
2033 template <typename _K2>
2034 _LIBCPP_INLINE_VISIBILITY
2035 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
2036 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
2039 _LIBCPP_INLINE_VISIBILITY
2040 pair<iterator,iterator> equal_range(const key_type& __k)
2041 {return __tree_.__equal_range_multi(__k);}
2042 _LIBCPP_INLINE_VISIBILITY
2043 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
2044 {return __tree_.__equal_range_multi(__k);}
2045 #if _LIBCPP_STD_VER > 11
2046 template <typename _K2>
2047 _LIBCPP_INLINE_VISIBILITY
2048 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
2049 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
2050 template <typename _K2>
2051 _LIBCPP_INLINE_VISIBILITY
2052 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
2053 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
2057 typedef typename __base::__node __node;
2058 typedef typename __base::__node_allocator __node_allocator;
2059 typedef typename __base::__node_pointer __node_pointer;
2060 typedef typename __base::__node_const_pointer __node_const_pointer;
2061 typedef __map_node_destructor<__node_allocator> _Dp;
2062 typedef unique_ptr<__node, _Dp> __node_holder;
2064 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2065 __node_holder __construct_node();
2066 template <class _A0>
2068 __construct_node(_A0&& __a0);
2069 #ifndef _LIBCPP_HAS_NO_VARIADICS
2070 template <class _A0, class _A1, class ..._Args>
2071 __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
2072 #endif // _LIBCPP_HAS_NO_VARIADICS
2073 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2076 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2078 template <class _Key, class _Tp, class _Compare, class _Allocator>
2079 multimap<_Key, _Tp, _Compare, _Allocator>::multimap(multimap&& __m, const allocator_type& __a)
2080 : __tree_(_VSTD::move(__m.__tree_), __a)
2082 if (__a != __m.get_allocator())
2084 const_iterator __e = cend();
2085 while (!__m.empty())
2086 __tree_.__insert_multi(__e.__i_,
2087 _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_));
2091 template <class _Key, class _Tp, class _Compare, class _Allocator>
2092 typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
2093 multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node()
2095 __node_allocator& __na = __tree_.__node_alloc();
2096 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
2097 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first));
2098 __h.get_deleter().__first_constructed = true;
2099 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
2100 __h.get_deleter().__second_constructed = true;
2104 template <class _Key, class _Tp, class _Compare, class _Allocator>
2105 template <class _A0>
2106 typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
2107 multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0)
2109 __node_allocator& __na = __tree_.__node_alloc();
2110 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
2111 __node_traits::construct(__na, _VSTD::addressof(__h->__value_), _VSTD::forward<_A0>(__a0));
2112 __h.get_deleter().__first_constructed = true;
2113 __h.get_deleter().__second_constructed = true;
2117 #ifndef _LIBCPP_HAS_NO_VARIADICS
2119 template <class _Key, class _Tp, class _Compare, class _Allocator>
2120 template <class _A0, class _A1, class ..._Args>
2121 typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
2122 multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args)
2124 __node_allocator& __na = __tree_.__node_alloc();
2125 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
2126 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
2127 _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
2128 _VSTD::forward<_Args>(__args)...);
2129 __h.get_deleter().__first_constructed = true;
2130 __h.get_deleter().__second_constructed = true;
2134 #endif // _LIBCPP_HAS_NO_VARIADICS
2135 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2137 #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
2139 template <class _Key, class _Tp, class _Compare, class _Allocator>
2140 template <class ..._Args>
2141 typename multimap<_Key, _Tp, _Compare, _Allocator>::iterator
2142 multimap<_Key, _Tp, _Compare, _Allocator>::emplace(_Args&& ...__args)
2144 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
2145 iterator __r = __tree_.__node_insert_multi(__h.get());
2150 template <class _Key, class _Tp, class _Compare, class _Allocator>
2151 template <class ..._Args>
2152 typename multimap<_Key, _Tp, _Compare, _Allocator>::iterator
2153 multimap<_Key, _Tp, _Compare, _Allocator>::emplace_hint(const_iterator __p,
2156 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
2157 iterator __r = __tree_.__node_insert_multi(__p.__i_, __h.get());
2162 #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
2164 template <class _Key, class _Tp, class _Compare, class _Allocator>
2165 inline _LIBCPP_INLINE_VISIBILITY
2167 operator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2168 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2170 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
2173 template <class _Key, class _Tp, class _Compare, class _Allocator>
2174 inline _LIBCPP_INLINE_VISIBILITY
2176 operator< (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2177 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2179 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
2182 template <class _Key, class _Tp, class _Compare, class _Allocator>
2183 inline _LIBCPP_INLINE_VISIBILITY
2185 operator!=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2186 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2188 return !(__x == __y);
2191 template <class _Key, class _Tp, class _Compare, class _Allocator>
2192 inline _LIBCPP_INLINE_VISIBILITY
2194 operator> (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2195 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2200 template <class _Key, class _Tp, class _Compare, class _Allocator>
2201 inline _LIBCPP_INLINE_VISIBILITY
2203 operator>=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2204 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2206 return !(__x < __y);
2209 template <class _Key, class _Tp, class _Compare, class _Allocator>
2210 inline _LIBCPP_INLINE_VISIBILITY
2212 operator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2213 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2215 return !(__y < __x);
2218 template <class _Key, class _Tp, class _Compare, class _Allocator>
2219 inline _LIBCPP_INLINE_VISIBILITY
2221 swap(multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2222 multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2223 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
2228 _LIBCPP_END_NAMESPACE_STD
2230 #endif // _LIBCPP_MAP