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);
82 map& operator=(const map& m);
83 map& operator=(map&& m)
85 allocator_type::propagate_on_container_move_assignment::value &&
86 is_nothrow_move_assignable<allocator_type>::value &&
87 is_nothrow_move_assignable<key_compare>::value);
88 map& operator=(initializer_list<value_type> il);
91 iterator begin() noexcept;
92 const_iterator begin() const noexcept;
93 iterator end() noexcept;
94 const_iterator end() const noexcept;
96 reverse_iterator rbegin() noexcept;
97 const_reverse_iterator rbegin() const noexcept;
98 reverse_iterator rend() noexcept;
99 const_reverse_iterator rend() const noexcept;
101 const_iterator cbegin() const noexcept;
102 const_iterator cend() const noexcept;
103 const_reverse_iterator crbegin() const noexcept;
104 const_reverse_iterator crend() const noexcept;
107 bool empty() const noexcept;
108 size_type size() const noexcept;
109 size_type max_size() const noexcept;
112 mapped_type& operator[](const key_type& k);
113 mapped_type& operator[](key_type&& k);
115 mapped_type& at(const key_type& k);
116 const mapped_type& at(const key_type& k) const;
119 template <class... Args>
120 pair<iterator, bool> emplace(Args&&... args);
121 template <class... Args>
122 iterator emplace_hint(const_iterator position, Args&&... args);
123 pair<iterator, bool> insert(const value_type& v);
125 pair<iterator, bool> insert(P&& p);
126 iterator insert(const_iterator position, const value_type& v);
128 iterator insert(const_iterator position, P&& p);
129 template <class InputIterator>
130 void insert(InputIterator first, InputIterator last);
131 void insert(initializer_list<value_type> il);
133 iterator erase(const_iterator position);
134 size_type erase(const key_type& k);
135 iterator erase(const_iterator first, const_iterator last);
136 void clear() noexcept;
140 __is_nothrow_swappable<key_compare>::value &&
141 (!allocator_type::propagate_on_container_swap::value ||
142 __is_nothrow_swappable<allocator_type>::value));
145 allocator_type get_allocator() const noexcept;
146 key_compare key_comp() const;
147 value_compare value_comp() const;
150 iterator find(const key_type& k);
151 const_iterator find(const key_type& k) const;
152 size_type count(const key_type& k) const;
153 iterator lower_bound(const key_type& k);
154 const_iterator lower_bound(const key_type& k) const;
155 iterator upper_bound(const key_type& k);
156 const_iterator upper_bound(const key_type& k) const;
157 pair<iterator,iterator> equal_range(const key_type& k);
158 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
161 template <class Key, class T, class Compare, class Allocator>
163 operator==(const map<Key, T, Compare, Allocator>& x,
164 const map<Key, T, Compare, Allocator>& y);
166 template <class Key, class T, class Compare, class Allocator>
168 operator< (const map<Key, T, Compare, Allocator>& x,
169 const map<Key, T, Compare, Allocator>& y);
171 template <class Key, class T, class Compare, class Allocator>
173 operator!=(const map<Key, T, Compare, Allocator>& x,
174 const map<Key, T, Compare, Allocator>& y);
176 template <class Key, class T, class Compare, class Allocator>
178 operator> (const map<Key, T, Compare, Allocator>& x,
179 const map<Key, T, Compare, Allocator>& y);
181 template <class Key, class T, class Compare, class Allocator>
183 operator>=(const map<Key, T, Compare, Allocator>& x,
184 const map<Key, T, Compare, Allocator>& y);
186 template <class Key, class T, class Compare, class Allocator>
188 operator<=(const map<Key, T, Compare, Allocator>& x,
189 const map<Key, T, Compare, Allocator>& y);
191 // specialized algorithms:
192 template <class Key, class T, class Compare, class Allocator>
194 swap(map<Key, T, Compare, Allocator>& x, map<Key, T, Compare, Allocator>& y)
195 noexcept(noexcept(x.swap(y)));
197 template <class Key, class T, class Compare = less<Key>,
198 class Allocator = allocator<pair<const Key, T>>>
203 typedef Key key_type;
204 typedef T mapped_type;
205 typedef pair<const key_type,mapped_type> value_type;
206 typedef Compare key_compare;
207 typedef Allocator allocator_type;
208 typedef typename allocator_type::reference reference;
209 typedef typename allocator_type::const_reference const_reference;
210 typedef typename allocator_type::size_type size_type;
211 typedef typename allocator_type::difference_type difference_type;
212 typedef typename allocator_type::pointer pointer;
213 typedef typename allocator_type::const_pointer const_pointer;
215 typedef implementation-defined iterator;
216 typedef implementation-defined const_iterator;
217 typedef std::reverse_iterator<iterator> reverse_iterator;
218 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
221 : public binary_function<value_type,value_type,bool>
223 friend class multimap;
226 value_compare(key_compare c);
228 bool operator()(const value_type& x, const value_type& y) const;
231 // construct/copy/destroy:
234 is_nothrow_default_constructible<allocator_type>::value &&
235 is_nothrow_default_constructible<key_compare>::value &&
236 is_nothrow_copy_constructible<key_compare>::value);
237 explicit multimap(const key_compare& comp);
238 multimap(const key_compare& comp, const allocator_type& a);
239 template <class InputIterator>
240 multimap(InputIterator first, InputIterator last, const key_compare& comp);
241 template <class InputIterator>
242 multimap(InputIterator first, InputIterator last, const key_compare& comp,
243 const allocator_type& a);
244 multimap(const multimap& m);
245 multimap(multimap&& m)
247 is_nothrow_move_constructible<allocator_type>::value &&
248 is_nothrow_move_constructible<key_compare>::value);
249 explicit multimap(const allocator_type& a);
250 multimap(const multimap& m, const allocator_type& a);
251 multimap(multimap&& m, const allocator_type& a);
252 multimap(initializer_list<value_type> il, const key_compare& comp = key_compare());
253 multimap(initializer_list<value_type> il, const key_compare& comp,
254 const allocator_type& a);
257 multimap& operator=(const multimap& m);
258 multimap& operator=(multimap&& m)
260 allocator_type::propagate_on_container_move_assignment::value &&
261 is_nothrow_move_assignable<allocator_type>::value &&
262 is_nothrow_move_assignable<key_compare>::value);
263 multimap& operator=(initializer_list<value_type> il);
266 iterator begin() noexcept;
267 const_iterator begin() const noexcept;
268 iterator end() noexcept;
269 const_iterator end() const noexcept;
271 reverse_iterator rbegin() noexcept;
272 const_reverse_iterator rbegin() const noexcept;
273 reverse_iterator rend() noexcept;
274 const_reverse_iterator rend() const noexcept;
276 const_iterator cbegin() const noexcept;
277 const_iterator cend() const noexcept;
278 const_reverse_iterator crbegin() const noexcept;
279 const_reverse_iterator crend() const noexcept;
282 bool empty() const noexcept;
283 size_type size() const noexcept;
284 size_type max_size() const noexcept;
287 template <class... Args>
288 iterator emplace(Args&&... args);
289 template <class... Args>
290 iterator emplace_hint(const_iterator position, Args&&... args);
291 iterator insert(const value_type& v);
293 iterator insert(P&& p);
294 iterator insert(const_iterator position, const value_type& v);
296 iterator insert(const_iterator position, P&& p);
297 template <class InputIterator>
298 void insert(InputIterator first, InputIterator last);
299 void insert(initializer_list<value_type> il);
301 iterator erase(const_iterator position);
302 size_type erase(const key_type& k);
303 iterator erase(const_iterator first, const_iterator last);
304 void clear() noexcept;
306 void swap(multimap& m)
308 __is_nothrow_swappable<key_compare>::value &&
309 (!allocator_type::propagate_on_container_swap::value ||
310 __is_nothrow_swappable<allocator_type>::value));
313 allocator_type get_allocator() const noexcept;
314 key_compare key_comp() const;
315 value_compare value_comp() const;
318 iterator find(const key_type& k);
319 const_iterator find(const key_type& k) const;
320 size_type count(const key_type& k) const;
321 iterator lower_bound(const key_type& k);
322 const_iterator lower_bound(const key_type& k) const;
323 iterator upper_bound(const key_type& k);
324 const_iterator upper_bound(const key_type& k) const;
325 pair<iterator,iterator> equal_range(const key_type& k);
326 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
329 template <class Key, class T, class Compare, class Allocator>
331 operator==(const multimap<Key, T, Compare, Allocator>& x,
332 const multimap<Key, T, Compare, Allocator>& y);
334 template <class Key, class T, class Compare, class Allocator>
336 operator< (const multimap<Key, T, Compare, Allocator>& x,
337 const multimap<Key, T, Compare, Allocator>& y);
339 template <class Key, class T, class Compare, class Allocator>
341 operator!=(const multimap<Key, T, Compare, Allocator>& x,
342 const multimap<Key, T, Compare, Allocator>& y);
344 template <class Key, class T, class Compare, class Allocator>
346 operator> (const multimap<Key, T, Compare, Allocator>& x,
347 const multimap<Key, T, Compare, Allocator>& y);
349 template <class Key, class T, class Compare, class Allocator>
351 operator>=(const multimap<Key, T, Compare, Allocator>& x,
352 const multimap<Key, T, Compare, Allocator>& y);
354 template <class Key, class T, class Compare, class Allocator>
356 operator<=(const multimap<Key, T, Compare, Allocator>& x,
357 const multimap<Key, T, Compare, Allocator>& y);
359 // specialized algorithms:
360 template <class Key, class T, class Compare, class Allocator>
362 swap(multimap<Key, T, Compare, Allocator>& x,
363 multimap<Key, T, Compare, Allocator>& y)
364 noexcept(noexcept(x.swap(y)));
375 #include <functional>
376 #include <initializer_list>
378 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
379 #pragma GCC system_header
382 _LIBCPP_BEGIN_NAMESPACE_STD
384 template <class _Key, class _CP, class _Compare, bool = is_empty<_Compare>::value
385 #if __has_feature(is_final)
386 && !__is_final(_Compare)
389 class __map_value_compare
393 _LIBCPP_INLINE_VISIBILITY
394 __map_value_compare()
395 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
397 _LIBCPP_INLINE_VISIBILITY
398 __map_value_compare(_Compare c)
399 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
401 _LIBCPP_INLINE_VISIBILITY
402 const _Compare& key_comp() const _NOEXCEPT {return *this;}
403 _LIBCPP_INLINE_VISIBILITY
404 bool operator()(const _CP& __x, const _CP& __y) const
405 {return static_cast<const _Compare&>(*this)(__x.__cc.first, __y.__cc.first);}
406 _LIBCPP_INLINE_VISIBILITY
407 bool operator()(const _CP& __x, const _Key& __y) const
408 {return static_cast<const _Compare&>(*this)(__x.__cc.first, __y);}
409 _LIBCPP_INLINE_VISIBILITY
410 bool operator()(const _Key& __x, const _CP& __y) const
411 {return static_cast<const _Compare&>(*this)(__x, __y.__cc.first);}
414 template <class _Key, class _CP, class _Compare>
415 class __map_value_compare<_Key, _CP, _Compare, false>
420 _LIBCPP_INLINE_VISIBILITY
421 __map_value_compare()
422 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
424 _LIBCPP_INLINE_VISIBILITY
425 __map_value_compare(_Compare c)
426 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
428 _LIBCPP_INLINE_VISIBILITY
429 const _Compare& key_comp() const _NOEXCEPT {return comp;}
431 _LIBCPP_INLINE_VISIBILITY
432 bool operator()(const _CP& __x, const _CP& __y) const
433 {return comp(__x.__cc.first, __y.__cc.first);}
434 _LIBCPP_INLINE_VISIBILITY
435 bool operator()(const _CP& __x, const _Key& __y) const
436 {return comp(__x.__cc.first, __y);}
437 _LIBCPP_INLINE_VISIBILITY
438 bool operator()(const _Key& __x, const _CP& __y) const
439 {return comp(__x, __y.__cc.first);}
442 template <class _Allocator>
443 class __map_node_destructor
445 typedef _Allocator allocator_type;
446 typedef allocator_traits<allocator_type> __alloc_traits;
447 typedef typename __alloc_traits::value_type::value_type value_type;
449 typedef typename __alloc_traits::pointer pointer;
451 typedef typename value_type::value_type::first_type first_type;
452 typedef typename value_type::value_type::second_type second_type;
454 allocator_type& __na_;
456 __map_node_destructor& operator=(const __map_node_destructor&);
459 bool __first_constructed;
460 bool __second_constructed;
462 _LIBCPP_INLINE_VISIBILITY
463 explicit __map_node_destructor(allocator_type& __na) _NOEXCEPT
465 __first_constructed(false),
466 __second_constructed(false)
469 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
470 _LIBCPP_INLINE_VISIBILITY
471 __map_node_destructor(__tree_node_destructor<allocator_type>&& __x) _NOEXCEPT
473 __first_constructed(__x.__value_constructed),
474 __second_constructed(__x.__value_constructed)
476 __x.__value_constructed = false;
478 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
480 _LIBCPP_INLINE_VISIBILITY
481 void operator()(pointer __p) _NOEXCEPT
483 if (__second_constructed)
484 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.second));
485 if (__first_constructed)
486 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.first));
488 __alloc_traits::deallocate(__na_, __p, 1);
492 template <class _Key, class _Tp, class _Compare, class _Allocator>
494 template <class _Key, class _Tp, class _Compare, class _Allocator>
496 template <class _TreeIterator> class __map_const_iterator;
498 template <class _TreeIterator>
499 class _LIBCPP_TYPE_VIS __map_iterator
503 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
504 typedef const typename _TreeIterator::value_type::value_type::first_type __key_type;
505 typedef typename _TreeIterator::value_type::value_type::second_type __mapped_type;
507 typedef bidirectional_iterator_tag iterator_category;
508 typedef pair<__key_type, __mapped_type> value_type;
509 typedef typename _TreeIterator::difference_type difference_type;
510 typedef value_type& reference;
511 typedef typename __pointer_traits::template
512 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
515 rebind<value_type>::other
519 _LIBCPP_INLINE_VISIBILITY
520 __map_iterator() _NOEXCEPT {}
522 _LIBCPP_INLINE_VISIBILITY
523 __map_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
525 _LIBCPP_INLINE_VISIBILITY
526 reference operator*() const {return __i_->__cc;}
527 _LIBCPP_INLINE_VISIBILITY
528 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
530 _LIBCPP_INLINE_VISIBILITY
531 __map_iterator& operator++() {++__i_; return *this;}
532 _LIBCPP_INLINE_VISIBILITY
533 __map_iterator operator++(int)
535 __map_iterator __t(*this);
540 _LIBCPP_INLINE_VISIBILITY
541 __map_iterator& operator--() {--__i_; return *this;}
542 _LIBCPP_INLINE_VISIBILITY
543 __map_iterator operator--(int)
545 __map_iterator __t(*this);
550 friend _LIBCPP_INLINE_VISIBILITY
551 bool operator==(const __map_iterator& __x, const __map_iterator& __y)
552 {return __x.__i_ == __y.__i_;}
554 _LIBCPP_INLINE_VISIBILITY
555 bool operator!=(const __map_iterator& __x, const __map_iterator& __y)
556 {return __x.__i_ != __y.__i_;}
558 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS map;
559 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS multimap;
560 template <class> friend class _LIBCPP_TYPE_VIS __map_const_iterator;
563 template <class _TreeIterator>
564 class _LIBCPP_TYPE_VIS __map_const_iterator
568 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
569 typedef const typename _TreeIterator::value_type::value_type::first_type __key_type;
570 typedef typename _TreeIterator::value_type::value_type::second_type __mapped_type;
572 typedef bidirectional_iterator_tag iterator_category;
573 typedef pair<__key_type, __mapped_type> value_type;
574 typedef typename _TreeIterator::difference_type difference_type;
575 typedef const value_type& reference;
576 typedef typename __pointer_traits::template
577 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
578 rebind<const value_type>
580 rebind<const value_type>::other
584 _LIBCPP_INLINE_VISIBILITY
585 __map_const_iterator() _NOEXCEPT {}
587 _LIBCPP_INLINE_VISIBILITY
588 __map_const_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
589 _LIBCPP_INLINE_VISIBILITY
590 __map_const_iterator(
591 __map_iterator<typename _TreeIterator::__non_const_iterator> __i)
595 _LIBCPP_INLINE_VISIBILITY
596 reference operator*() const {return __i_->__cc;}
597 _LIBCPP_INLINE_VISIBILITY
598 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
600 _LIBCPP_INLINE_VISIBILITY
601 __map_const_iterator& operator++() {++__i_; return *this;}
602 _LIBCPP_INLINE_VISIBILITY
603 __map_const_iterator operator++(int)
605 __map_const_iterator __t(*this);
610 _LIBCPP_INLINE_VISIBILITY
611 __map_const_iterator& operator--() {--__i_; return *this;}
612 _LIBCPP_INLINE_VISIBILITY
613 __map_const_iterator operator--(int)
615 __map_const_iterator __t(*this);
620 friend _LIBCPP_INLINE_VISIBILITY
621 bool operator==(const __map_const_iterator& __x, const __map_const_iterator& __y)
622 {return __x.__i_ == __y.__i_;}
623 friend _LIBCPP_INLINE_VISIBILITY
624 bool operator!=(const __map_const_iterator& __x, const __map_const_iterator& __y)
625 {return __x.__i_ != __y.__i_;}
627 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS map;
628 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS multimap;
629 template <class, class, class> friend class _LIBCPP_TYPE_VIS __tree_const_iterator;
632 template <class _Key, class _Tp, class _Compare = less<_Key>,
633 class _Allocator = allocator<pair<const _Key, _Tp> > >
634 class _LIBCPP_TYPE_VIS map
638 typedef _Key key_type;
639 typedef _Tp mapped_type;
640 typedef pair<const key_type, mapped_type> value_type;
641 typedef pair<key_type, mapped_type> __nc_value_type;
642 typedef _Compare key_compare;
643 typedef _Allocator allocator_type;
644 typedef value_type& reference;
645 typedef const value_type& const_reference;
647 class _LIBCPP_TYPE_VIS value_compare
648 : public binary_function<value_type, value_type, bool>
654 _LIBCPP_INLINE_VISIBILITY value_compare(key_compare c) : comp(c) {}
656 _LIBCPP_INLINE_VISIBILITY
657 bool operator()(const value_type& __x, const value_type& __y) const
658 {return comp(__x.first, __y.first);}
663 #if __cplusplus >= 201103L
666 typedef typename map::value_type value_type;
667 typedef typename map::__nc_value_type __nc_value_type;
669 __nc_value_type __nc;
671 template <class ..._Args>
672 __value_type(_Args&& ...__args)
673 : __cc(std::forward<_Args>(__args)...) {}
675 __value_type(const __value_type& __v)
676 : __cc(std::move(__v.__cc)) {}
678 __value_type(__value_type&& __v)
679 : __nc(std::move(__v.__nc)) {}
681 __value_type& operator=(const __value_type& __v)
682 {__nc = __v.__cc; return *this;}
684 __value_type& operator=(__value_type&& __v)
685 {__nc = std::move(__v.__nc); return *this;}
687 ~__value_type() {__cc.~value_type();}
692 typedef typename map::value_type value_type;
698 __value_type(const _A0& __a0)
701 template <class _A0, class _A1>
702 __value_type(const _A0& __a0, const _A1& __a1)
703 : __cc(__a0, __a1) {}
706 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
707 typedef typename allocator_traits<allocator_type>::template
708 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
709 rebind_alloc<__value_type>
711 rebind_alloc<__value_type>::other
714 typedef __tree<__value_type, __vc, __allocator_type> __base;
715 typedef typename __base::__node_traits __node_traits;
716 typedef allocator_traits<allocator_type> __alloc_traits;
721 typedef typename __alloc_traits::pointer pointer;
722 typedef typename __alloc_traits::const_pointer const_pointer;
723 typedef typename __alloc_traits::size_type size_type;
724 typedef typename __alloc_traits::difference_type difference_type;
725 typedef __map_iterator<typename __base::iterator> iterator;
726 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
727 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
728 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
730 _LIBCPP_INLINE_VISIBILITY
731 explicit map(const key_compare& __comp = key_compare())
733 is_nothrow_default_constructible<allocator_type>::value &&
734 is_nothrow_default_constructible<key_compare>::value &&
735 is_nothrow_copy_constructible<key_compare>::value)
736 : __tree_(__vc(__comp)) {}
738 _LIBCPP_INLINE_VISIBILITY
739 explicit map(const key_compare& __comp, const allocator_type& __a)
740 : __tree_(__vc(__comp), __a) {}
742 template <class _InputIterator>
743 _LIBCPP_INLINE_VISIBILITY
744 map(_InputIterator __f, _InputIterator __l,
745 const key_compare& __comp = key_compare())
746 : __tree_(__vc(__comp))
751 template <class _InputIterator>
752 _LIBCPP_INLINE_VISIBILITY
753 map(_InputIterator __f, _InputIterator __l,
754 const key_compare& __comp, const allocator_type& __a)
755 : __tree_(__vc(__comp), __a)
760 _LIBCPP_INLINE_VISIBILITY
762 : __tree_(__m.__tree_)
764 insert(__m.begin(), __m.end());
767 _LIBCPP_INLINE_VISIBILITY
768 map& operator=(const map& __m)
770 #if __cplusplus >= 201103L
771 __tree_ = __m.__tree_;
774 __tree_.value_comp() = __m.__tree_.value_comp();
775 __tree_.__copy_assign_alloc(__m.__tree_);
776 insert(__m.begin(), __m.end());
781 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
783 _LIBCPP_INLINE_VISIBILITY
785 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
786 : __tree_(_VSTD::move(__m.__tree_))
790 map(map&& __m, const allocator_type& __a);
792 _LIBCPP_INLINE_VISIBILITY
793 map& operator=(map&& __m)
794 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
796 __tree_ = _VSTD::move(__m.__tree_);
800 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
802 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
804 _LIBCPP_INLINE_VISIBILITY
805 map(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
806 : __tree_(__vc(__comp))
808 insert(__il.begin(), __il.end());
811 _LIBCPP_INLINE_VISIBILITY
812 map(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
813 : __tree_(__vc(__comp), __a)
815 insert(__il.begin(), __il.end());
818 _LIBCPP_INLINE_VISIBILITY
819 map& operator=(initializer_list<value_type> __il)
821 __tree_.__assign_unique(__il.begin(), __il.end());
825 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
827 _LIBCPP_INLINE_VISIBILITY
828 explicit map(const allocator_type& __a)
833 _LIBCPP_INLINE_VISIBILITY
834 map(const map& __m, const allocator_type& __a)
835 : __tree_(__m.__tree_.value_comp(), __a)
837 insert(__m.begin(), __m.end());
840 _LIBCPP_INLINE_VISIBILITY
841 iterator begin() _NOEXCEPT {return __tree_.begin();}
842 _LIBCPP_INLINE_VISIBILITY
843 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
844 _LIBCPP_INLINE_VISIBILITY
845 iterator end() _NOEXCEPT {return __tree_.end();}
846 _LIBCPP_INLINE_VISIBILITY
847 const_iterator end() const _NOEXCEPT {return __tree_.end();}
849 _LIBCPP_INLINE_VISIBILITY
850 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
851 _LIBCPP_INLINE_VISIBILITY
852 const_reverse_iterator rbegin() const _NOEXCEPT
853 {return const_reverse_iterator(end());}
854 _LIBCPP_INLINE_VISIBILITY
855 reverse_iterator rend() _NOEXCEPT
856 {return reverse_iterator(begin());}
857 _LIBCPP_INLINE_VISIBILITY
858 const_reverse_iterator rend() const _NOEXCEPT
859 {return const_reverse_iterator(begin());}
861 _LIBCPP_INLINE_VISIBILITY
862 const_iterator cbegin() const _NOEXCEPT {return begin();}
863 _LIBCPP_INLINE_VISIBILITY
864 const_iterator cend() const _NOEXCEPT {return end();}
865 _LIBCPP_INLINE_VISIBILITY
866 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
867 _LIBCPP_INLINE_VISIBILITY
868 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
870 _LIBCPP_INLINE_VISIBILITY
871 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
872 _LIBCPP_INLINE_VISIBILITY
873 size_type size() const _NOEXCEPT {return __tree_.size();}
874 _LIBCPP_INLINE_VISIBILITY
875 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
877 mapped_type& operator[](const key_type& __k);
878 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
879 mapped_type& operator[](key_type&& __k);
882 mapped_type& at(const key_type& __k);
883 const mapped_type& at(const key_type& __k) const;
885 _LIBCPP_INLINE_VISIBILITY
886 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
887 _LIBCPP_INLINE_VISIBILITY
888 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
889 _LIBCPP_INLINE_VISIBILITY
890 value_compare value_comp() const {return value_compare(__tree_.value_comp().key_comp());}
892 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
893 #ifndef _LIBCPP_HAS_NO_VARIADICS
895 template <class ..._Args>
897 emplace(_Args&& ...__args);
899 template <class ..._Args>
901 emplace_hint(const_iterator __p, _Args&& ...__args);
903 #endif // _LIBCPP_HAS_NO_VARIADICS
906 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
907 _LIBCPP_INLINE_VISIBILITY
908 pair<iterator, bool> insert(_Pp&& __p)
909 {return __tree_.__insert_unique(_VSTD::forward<_Pp>(__p));}
912 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
913 _LIBCPP_INLINE_VISIBILITY
914 iterator insert(const_iterator __pos, _Pp&& __p)
915 {return __tree_.__insert_unique(__pos.__i_, _VSTD::forward<_Pp>(__p));}
917 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
919 _LIBCPP_INLINE_VISIBILITY
921 insert(const value_type& __v) {return __tree_.__insert_unique(__v);}
923 _LIBCPP_INLINE_VISIBILITY
925 insert(const_iterator __p, const value_type& __v)
926 {return __tree_.__insert_unique(__p.__i_, __v);}
928 template <class _InputIterator>
929 _LIBCPP_INLINE_VISIBILITY
930 void insert(_InputIterator __f, _InputIterator __l)
932 for (const_iterator __e = cend(); __f != __l; ++__f)
933 insert(__e.__i_, *__f);
936 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
938 _LIBCPP_INLINE_VISIBILITY
939 void insert(initializer_list<value_type> __il)
940 {insert(__il.begin(), __il.end());}
942 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
944 _LIBCPP_INLINE_VISIBILITY
945 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
946 _LIBCPP_INLINE_VISIBILITY
947 size_type erase(const key_type& __k)
948 {return __tree_.__erase_unique(__k);}
949 _LIBCPP_INLINE_VISIBILITY
950 iterator erase(const_iterator __f, const_iterator __l)
951 {return __tree_.erase(__f.__i_, __l.__i_);}
952 _LIBCPP_INLINE_VISIBILITY
953 void clear() _NOEXCEPT {__tree_.clear();}
955 _LIBCPP_INLINE_VISIBILITY
957 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
958 {__tree_.swap(__m.__tree_);}
960 _LIBCPP_INLINE_VISIBILITY
961 iterator find(const key_type& __k) {return __tree_.find(__k);}
962 _LIBCPP_INLINE_VISIBILITY
963 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
964 _LIBCPP_INLINE_VISIBILITY
965 size_type count(const key_type& __k) const
966 {return __tree_.__count_unique(__k);}
967 _LIBCPP_INLINE_VISIBILITY
968 iterator lower_bound(const key_type& __k)
969 {return __tree_.lower_bound(__k);}
970 _LIBCPP_INLINE_VISIBILITY
971 const_iterator lower_bound(const key_type& __k) const
972 {return __tree_.lower_bound(__k);}
973 _LIBCPP_INLINE_VISIBILITY
974 iterator upper_bound(const key_type& __k)
975 {return __tree_.upper_bound(__k);}
976 _LIBCPP_INLINE_VISIBILITY
977 const_iterator upper_bound(const key_type& __k) const
978 {return __tree_.upper_bound(__k);}
979 _LIBCPP_INLINE_VISIBILITY
980 pair<iterator,iterator> equal_range(const key_type& __k)
981 {return __tree_.__equal_range_unique(__k);}
982 _LIBCPP_INLINE_VISIBILITY
983 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
984 {return __tree_.__equal_range_unique(__k);}
987 typedef typename __base::__node __node;
988 typedef typename __base::__node_allocator __node_allocator;
989 typedef typename __base::__node_pointer __node_pointer;
990 typedef typename __base::__node_const_pointer __node_const_pointer;
991 typedef typename __base::__node_base_pointer __node_base_pointer;
992 typedef typename __base::__node_base_const_pointer __node_base_const_pointer;
993 typedef __map_node_destructor<__node_allocator> _Dp;
994 typedef unique_ptr<__node, _Dp> __node_holder;
996 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
997 __node_holder __construct_node();
999 __node_holder __construct_node(_A0&& __a0);
1000 __node_holder __construct_node_with_key(key_type&& __k);
1001 #ifndef _LIBCPP_HAS_NO_VARIADICS
1002 template <class _A0, class _A1, class ..._Args>
1003 __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
1004 #endif // _LIBCPP_HAS_NO_VARIADICS
1006 __node_holder __construct_node_with_key(const key_type& __k);
1008 __node_base_pointer&
1009 __find_equal_key(__node_base_pointer& __parent, const key_type& __k);
1010 __node_base_const_pointer
1011 __find_equal_key(__node_base_const_pointer& __parent, const key_type& __k) const;
1014 // Find place to insert if __k doesn't exist
1015 // Set __parent to parent of null leaf
1016 // Return reference to null leaf
1017 // If __k exists, set parent to node of __k and return reference to node of __k
1018 template <class _Key, class _Tp, class _Compare, class _Allocator>
1019 typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_pointer&
1020 map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(__node_base_pointer& __parent,
1021 const key_type& __k)
1023 __node_pointer __nd = __tree_.__root();
1024 if (__nd != nullptr)
1028 if (__tree_.value_comp().key_comp()(__k, __nd->__value_.__cc.first))
1030 if (__nd->__left_ != nullptr)
1031 __nd = static_cast<__node_pointer>(__nd->__left_);
1034 __parent = static_cast<__node_base_pointer>(__nd);
1035 return __parent->__left_;
1038 else if (__tree_.value_comp().key_comp()(__nd->__value_.__cc.first, __k))
1040 if (__nd->__right_ != nullptr)
1041 __nd = static_cast<__node_pointer>(__nd->__right_);
1044 __parent = static_cast<__node_base_pointer>(__nd);
1045 return __parent->__right_;
1050 __parent = static_cast<__node_base_pointer>(__nd);
1055 __parent = static_cast<__node_base_pointer>(__tree_.__end_node());
1056 return __parent->__left_;
1060 // Set __parent to parent of null leaf and
1061 // return reference to null leaf iv __k does not exist.
1062 // If __k exists, set parent to node of __k and return reference to node of __k
1063 template <class _Key, class _Tp, class _Compare, class _Allocator>
1064 typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_const_pointer
1065 map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(__node_base_const_pointer& __parent,
1066 const key_type& __k) const
1068 __node_const_pointer __nd = __tree_.__root();
1069 if (__nd != nullptr)
1073 if (__tree_.value_comp().key_comp()(__k, __nd->__value_.__cc.first))
1075 if (__nd->__left_ != nullptr)
1076 __nd = static_cast<__node_pointer>(__nd->__left_);
1079 __parent = static_cast<__node_base_pointer>(__nd);
1080 return const_cast<const __node_base_const_pointer&>(__parent->__left_);
1083 else if (__tree_.value_comp().key_comp()(__nd->__value_.__cc.first, __k))
1085 if (__nd->__right_ != nullptr)
1086 __nd = static_cast<__node_pointer>(__nd->__right_);
1089 __parent = static_cast<__node_base_pointer>(__nd);
1090 return const_cast<const __node_base_const_pointer&>(__parent->__right_);
1095 __parent = static_cast<__node_base_pointer>(__nd);
1100 __parent = static_cast<__node_base_pointer>(__tree_.__end_node());
1101 return const_cast<const __node_base_const_pointer&>(__parent->__left_);
1104 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1106 template <class _Key, class _Tp, class _Compare, class _Allocator>
1107 map<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a)
1108 : __tree_(_VSTD::move(__m.__tree_), __a)
1110 if (__a != __m.get_allocator())
1112 const_iterator __e = cend();
1113 while (!__m.empty())
1114 __tree_.__insert_unique(__e.__i_,
1115 _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_));
1119 template <class _Key, class _Tp, class _Compare, class _Allocator>
1120 typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1121 map<_Key, _Tp, _Compare, _Allocator>::__construct_node()
1123 __node_allocator& __na = __tree_.__node_alloc();
1124 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1125 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first));
1126 __h.get_deleter().__first_constructed = true;
1127 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
1128 __h.get_deleter().__second_constructed = true;
1132 template <class _Key, class _Tp, class _Compare, class _Allocator>
1133 template <class _A0>
1134 typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1135 map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0)
1137 __node_allocator& __na = __tree_.__node_alloc();
1138 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1139 __node_traits::construct(__na, _VSTD::addressof(__h->__value_), _VSTD::forward<_A0>(__a0));
1140 __h.get_deleter().__first_constructed = true;
1141 __h.get_deleter().__second_constructed = true;
1145 template <class _Key, class _Tp, class _Compare, class _Allocator>
1146 typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1147 map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(key_type&& __k)
1149 __node_allocator& __na = __tree_.__node_alloc();
1150 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1151 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), _VSTD::move(__k));
1152 __h.get_deleter().__first_constructed = true;
1153 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
1154 __h.get_deleter().__second_constructed = true;
1155 return _VSTD::move(__h);
1158 #ifndef _LIBCPP_HAS_NO_VARIADICS
1160 template <class _Key, class _Tp, class _Compare, class _Allocator>
1161 template <class _A0, class _A1, class ..._Args>
1162 typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1163 map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args)
1165 __node_allocator& __na = __tree_.__node_alloc();
1166 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1167 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
1168 _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
1169 _VSTD::forward<_Args>(__args)...);
1170 __h.get_deleter().__first_constructed = true;
1171 __h.get_deleter().__second_constructed = true;
1175 #endif // _LIBCPP_HAS_NO_VARIADICS
1177 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1179 template <class _Key, class _Tp, class _Compare, class _Allocator>
1180 typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1181 map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(const key_type& __k)
1183 __node_allocator& __na = __tree_.__node_alloc();
1184 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1185 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), __k);
1186 __h.get_deleter().__first_constructed = true;
1187 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
1188 __h.get_deleter().__second_constructed = true;
1189 return _VSTD::move(__h);
1192 template <class _Key, class _Tp, class _Compare, class _Allocator>
1194 map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k)
1196 __node_base_pointer __parent;
1197 __node_base_pointer& __child = __find_equal_key(__parent, __k);
1198 __node_pointer __r = static_cast<__node_pointer>(__child);
1199 if (__child == nullptr)
1201 __node_holder __h = __construct_node_with_key(__k);
1202 __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
1203 __r = __h.release();
1205 return __r->__value_.__cc.second;
1208 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1210 template <class _Key, class _Tp, class _Compare, class _Allocator>
1212 map<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k)
1214 __node_base_pointer __parent;
1215 __node_base_pointer& __child = __find_equal_key(__parent, __k);
1216 __node_pointer __r = static_cast<__node_pointer>(__child);
1217 if (__child == nullptr)
1219 __node_holder __h = __construct_node_with_key(_VSTD::move(__k));
1220 __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
1221 __r = __h.release();
1223 return __r->__value_.__cc.second;
1226 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1228 template <class _Key, class _Tp, class _Compare, class _Allocator>
1230 map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k)
1232 __node_base_pointer __parent;
1233 __node_base_pointer& __child = __find_equal_key(__parent, __k);
1234 #ifndef _LIBCPP_NO_EXCEPTIONS
1235 if (__child == nullptr)
1236 throw out_of_range("map::at: key not found");
1237 #endif // _LIBCPP_NO_EXCEPTIONS
1238 return static_cast<__node_pointer>(__child)->__value_.__cc.second;
1241 template <class _Key, class _Tp, class _Compare, class _Allocator>
1243 map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const
1245 __node_base_const_pointer __parent;
1246 __node_base_const_pointer __child = __find_equal_key(__parent, __k);
1247 #ifndef _LIBCPP_NO_EXCEPTIONS
1248 if (__child == nullptr)
1249 throw out_of_range("map::at: key not found");
1250 #endif // _LIBCPP_NO_EXCEPTIONS
1251 return static_cast<__node_const_pointer>(__child)->__value_.__cc.second;
1254 #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1256 template <class _Key, class _Tp, class _Compare, class _Allocator>
1257 template <class ..._Args>
1258 pair<typename map<_Key, _Tp, _Compare, _Allocator>::iterator, bool>
1259 map<_Key, _Tp, _Compare, _Allocator>::emplace(_Args&& ...__args)
1261 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
1262 pair<iterator, bool> __r = __tree_.__node_insert_unique(__h.get());
1268 template <class _Key, class _Tp, class _Compare, class _Allocator>
1269 template <class ..._Args>
1270 typename map<_Key, _Tp, _Compare, _Allocator>::iterator
1271 map<_Key, _Tp, _Compare, _Allocator>::emplace_hint(const_iterator __p,
1274 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
1275 iterator __r = __tree_.__node_insert_unique(__p.__i_, __h.get());
1276 if (__r.__i_.__ptr_ == __h.get())
1281 #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1283 template <class _Key, class _Tp, class _Compare, class _Allocator>
1284 inline _LIBCPP_INLINE_VISIBILITY
1286 operator==(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1287 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1289 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
1292 template <class _Key, class _Tp, class _Compare, class _Allocator>
1293 inline _LIBCPP_INLINE_VISIBILITY
1295 operator< (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1296 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1298 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
1301 template <class _Key, class _Tp, class _Compare, class _Allocator>
1302 inline _LIBCPP_INLINE_VISIBILITY
1304 operator!=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1305 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1307 return !(__x == __y);
1310 template <class _Key, class _Tp, class _Compare, class _Allocator>
1311 inline _LIBCPP_INLINE_VISIBILITY
1313 operator> (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1314 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1319 template <class _Key, class _Tp, class _Compare, class _Allocator>
1320 inline _LIBCPP_INLINE_VISIBILITY
1322 operator>=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1323 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1325 return !(__x < __y);
1328 template <class _Key, class _Tp, class _Compare, class _Allocator>
1329 inline _LIBCPP_INLINE_VISIBILITY
1331 operator<=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1332 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1334 return !(__y < __x);
1337 template <class _Key, class _Tp, class _Compare, class _Allocator>
1338 inline _LIBCPP_INLINE_VISIBILITY
1340 swap(map<_Key, _Tp, _Compare, _Allocator>& __x,
1341 map<_Key, _Tp, _Compare, _Allocator>& __y)
1342 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
1347 template <class _Key, class _Tp, class _Compare = less<_Key>,
1348 class _Allocator = allocator<pair<const _Key, _Tp> > >
1349 class _LIBCPP_TYPE_VIS multimap
1353 typedef _Key key_type;
1354 typedef _Tp mapped_type;
1355 typedef pair<const key_type, mapped_type> value_type;
1356 typedef pair<key_type, mapped_type> __nc_value_type;
1357 typedef _Compare key_compare;
1358 typedef _Allocator allocator_type;
1359 typedef value_type& reference;
1360 typedef const value_type& const_reference;
1362 class _LIBCPP_TYPE_VIS value_compare
1363 : public binary_function<value_type, value_type, bool>
1365 friend class multimap;
1369 _LIBCPP_INLINE_VISIBILITY
1370 value_compare(key_compare c) : comp(c) {}
1372 _LIBCPP_INLINE_VISIBILITY
1373 bool operator()(const value_type& __x, const value_type& __y) const
1374 {return comp(__x.first, __y.first);}
1378 #if __cplusplus >= 201103L
1381 typedef typename multimap::value_type value_type;
1382 typedef typename multimap::__nc_value_type __nc_value_type;
1384 __nc_value_type __nc;
1386 template <class ..._Args>
1387 __value_type(_Args&& ...__args)
1388 : __cc(std::forward<_Args>(__args)...) {}
1390 __value_type(const __value_type& __v)
1391 : __cc(std::move(__v.__cc)) {}
1393 __value_type(__value_type&& __v)
1394 : __nc(std::move(__v.__nc)) {}
1396 __value_type& operator=(const __value_type& __v)
1397 {__nc = __v.__cc; return *this;}
1399 __value_type& operator=(__value_type&& __v)
1400 {__nc = std::move(__v.__nc); return *this;}
1402 ~__value_type() {__cc.~value_type();}
1407 typedef typename multimap::value_type value_type;
1412 template <class _A0>
1413 __value_type(const _A0& __a0)
1416 template <class _A0, class _A1>
1417 __value_type(const _A0& __a0, const _A1& __a1)
1418 : __cc(__a0, __a1) {}
1421 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
1422 typedef typename allocator_traits<allocator_type>::template
1423 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1424 rebind_alloc<__value_type>
1426 rebind_alloc<__value_type>::other
1429 typedef __tree<__value_type, __vc, __allocator_type> __base;
1430 typedef typename __base::__node_traits __node_traits;
1431 typedef allocator_traits<allocator_type> __alloc_traits;
1436 typedef typename __alloc_traits::pointer pointer;
1437 typedef typename __alloc_traits::const_pointer const_pointer;
1438 typedef typename __alloc_traits::size_type size_type;
1439 typedef typename __alloc_traits::difference_type difference_type;
1440 typedef __map_iterator<typename __base::iterator> iterator;
1441 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
1442 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1443 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
1445 _LIBCPP_INLINE_VISIBILITY
1446 explicit multimap(const key_compare& __comp = key_compare())
1448 is_nothrow_default_constructible<allocator_type>::value &&
1449 is_nothrow_default_constructible<key_compare>::value &&
1450 is_nothrow_copy_constructible<key_compare>::value)
1451 : __tree_(__vc(__comp)) {}
1453 _LIBCPP_INLINE_VISIBILITY
1454 explicit multimap(const key_compare& __comp, const allocator_type& __a)
1455 : __tree_(__vc(__comp), __a) {}
1457 template <class _InputIterator>
1458 _LIBCPP_INLINE_VISIBILITY
1459 multimap(_InputIterator __f, _InputIterator __l,
1460 const key_compare& __comp = key_compare())
1461 : __tree_(__vc(__comp))
1466 template <class _InputIterator>
1467 _LIBCPP_INLINE_VISIBILITY
1468 multimap(_InputIterator __f, _InputIterator __l,
1469 const key_compare& __comp, const allocator_type& __a)
1470 : __tree_(__vc(__comp), __a)
1475 _LIBCPP_INLINE_VISIBILITY
1476 multimap(const multimap& __m)
1477 : __tree_(__m.__tree_.value_comp(),
1478 __alloc_traits::select_on_container_copy_construction(__m.__tree_.__alloc()))
1480 insert(__m.begin(), __m.end());
1483 _LIBCPP_INLINE_VISIBILITY
1484 multimap& operator=(const multimap& __m)
1486 #if __cplusplus >= 201103L
1487 __tree_ = __m.__tree_;
1490 __tree_.value_comp() = __m.__tree_.value_comp();
1491 __tree_.__copy_assign_alloc(__m.__tree_);
1492 insert(__m.begin(), __m.end());
1497 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1499 _LIBCPP_INLINE_VISIBILITY
1500 multimap(multimap&& __m)
1501 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
1502 : __tree_(_VSTD::move(__m.__tree_))
1506 multimap(multimap&& __m, const allocator_type& __a);
1508 _LIBCPP_INLINE_VISIBILITY
1509 multimap& operator=(multimap&& __m)
1510 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
1512 __tree_ = _VSTD::move(__m.__tree_);
1516 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1518 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1520 _LIBCPP_INLINE_VISIBILITY
1521 multimap(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
1522 : __tree_(__vc(__comp))
1524 insert(__il.begin(), __il.end());
1527 _LIBCPP_INLINE_VISIBILITY
1528 multimap(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
1529 : __tree_(__vc(__comp), __a)
1531 insert(__il.begin(), __il.end());
1534 _LIBCPP_INLINE_VISIBILITY
1535 multimap& operator=(initializer_list<value_type> __il)
1537 __tree_.__assign_multi(__il.begin(), __il.end());
1541 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1543 _LIBCPP_INLINE_VISIBILITY
1544 explicit multimap(const allocator_type& __a)
1549 _LIBCPP_INLINE_VISIBILITY
1550 multimap(const multimap& __m, const allocator_type& __a)
1551 : __tree_(__m.__tree_.value_comp(), __a)
1553 insert(__m.begin(), __m.end());
1556 _LIBCPP_INLINE_VISIBILITY
1557 iterator begin() _NOEXCEPT {return __tree_.begin();}
1558 _LIBCPP_INLINE_VISIBILITY
1559 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
1560 _LIBCPP_INLINE_VISIBILITY
1561 iterator end() _NOEXCEPT {return __tree_.end();}
1562 _LIBCPP_INLINE_VISIBILITY
1563 const_iterator end() const _NOEXCEPT {return __tree_.end();}
1565 _LIBCPP_INLINE_VISIBILITY
1566 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
1567 _LIBCPP_INLINE_VISIBILITY
1568 const_reverse_iterator rbegin() const _NOEXCEPT
1569 {return const_reverse_iterator(end());}
1570 _LIBCPP_INLINE_VISIBILITY
1571 reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
1572 _LIBCPP_INLINE_VISIBILITY
1573 const_reverse_iterator rend() const _NOEXCEPT
1574 {return const_reverse_iterator(begin());}
1576 _LIBCPP_INLINE_VISIBILITY
1577 const_iterator cbegin() const _NOEXCEPT {return begin();}
1578 _LIBCPP_INLINE_VISIBILITY
1579 const_iterator cend() const _NOEXCEPT {return end();}
1580 _LIBCPP_INLINE_VISIBILITY
1581 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
1582 _LIBCPP_INLINE_VISIBILITY
1583 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
1585 _LIBCPP_INLINE_VISIBILITY
1586 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
1587 _LIBCPP_INLINE_VISIBILITY
1588 size_type size() const _NOEXCEPT {return __tree_.size();}
1589 _LIBCPP_INLINE_VISIBILITY
1590 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
1592 _LIBCPP_INLINE_VISIBILITY
1593 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
1594 _LIBCPP_INLINE_VISIBILITY
1595 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
1596 _LIBCPP_INLINE_VISIBILITY
1597 value_compare value_comp() const
1598 {return value_compare(__tree_.value_comp().key_comp());}
1600 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1601 #ifndef _LIBCPP_HAS_NO_VARIADICS
1603 template <class ..._Args>
1605 emplace(_Args&& ...__args);
1607 template <class ..._Args>
1609 emplace_hint(const_iterator __p, _Args&& ...__args);
1611 #endif // _LIBCPP_HAS_NO_VARIADICS
1613 template <class _Pp,
1614 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
1615 _LIBCPP_INLINE_VISIBILITY
1616 iterator insert(_Pp&& __p)
1617 {return __tree_.__insert_multi(_VSTD::forward<_Pp>(__p));}
1619 template <class _Pp,
1620 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
1621 _LIBCPP_INLINE_VISIBILITY
1622 iterator insert(const_iterator __pos, _Pp&& __p)
1623 {return __tree_.__insert_multi(__pos.__i_, _VSTD::forward<_Pp>(__p));}
1625 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1627 _LIBCPP_INLINE_VISIBILITY
1628 iterator insert(const value_type& __v) {return __tree_.__insert_multi(__v);}
1630 _LIBCPP_INLINE_VISIBILITY
1631 iterator insert(const_iterator __p, const value_type& __v)
1632 {return __tree_.__insert_multi(__p.__i_, __v);}
1634 template <class _InputIterator>
1635 _LIBCPP_INLINE_VISIBILITY
1636 void insert(_InputIterator __f, _InputIterator __l)
1638 for (const_iterator __e = cend(); __f != __l; ++__f)
1639 __tree_.__insert_multi(__e.__i_, *__f);
1642 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1644 _LIBCPP_INLINE_VISIBILITY
1645 void insert(initializer_list<value_type> __il)
1646 {insert(__il.begin(), __il.end());}
1648 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1650 _LIBCPP_INLINE_VISIBILITY
1651 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
1652 _LIBCPP_INLINE_VISIBILITY
1653 size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
1654 _LIBCPP_INLINE_VISIBILITY
1655 iterator erase(const_iterator __f, const_iterator __l)
1656 {return __tree_.erase(__f.__i_, __l.__i_);}
1657 _LIBCPP_INLINE_VISIBILITY
1658 void clear() {__tree_.clear();}
1660 _LIBCPP_INLINE_VISIBILITY
1661 void swap(multimap& __m)
1662 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1663 {__tree_.swap(__m.__tree_);}
1665 _LIBCPP_INLINE_VISIBILITY
1666 iterator find(const key_type& __k) {return __tree_.find(__k);}
1667 _LIBCPP_INLINE_VISIBILITY
1668 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
1669 _LIBCPP_INLINE_VISIBILITY
1670 size_type count(const key_type& __k) const
1671 {return __tree_.__count_multi(__k);}
1672 _LIBCPP_INLINE_VISIBILITY
1673 iterator lower_bound(const key_type& __k)
1674 {return __tree_.lower_bound(__k);}
1675 _LIBCPP_INLINE_VISIBILITY
1676 const_iterator lower_bound(const key_type& __k) const
1677 {return __tree_.lower_bound(__k);}
1678 _LIBCPP_INLINE_VISIBILITY
1679 iterator upper_bound(const key_type& __k)
1680 {return __tree_.upper_bound(__k);}
1681 _LIBCPP_INLINE_VISIBILITY
1682 const_iterator upper_bound(const key_type& __k) const
1683 {return __tree_.upper_bound(__k);}
1684 _LIBCPP_INLINE_VISIBILITY
1685 pair<iterator,iterator> equal_range(const key_type& __k)
1686 {return __tree_.__equal_range_multi(__k);}
1687 _LIBCPP_INLINE_VISIBILITY
1688 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
1689 {return __tree_.__equal_range_multi(__k);}
1692 typedef typename __base::__node __node;
1693 typedef typename __base::__node_allocator __node_allocator;
1694 typedef typename __base::__node_pointer __node_pointer;
1695 typedef typename __base::__node_const_pointer __node_const_pointer;
1696 typedef __map_node_destructor<__node_allocator> _Dp;
1697 typedef unique_ptr<__node, _Dp> __node_holder;
1699 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1700 __node_holder __construct_node();
1701 template <class _A0>
1703 __construct_node(_A0&& __a0);
1704 #ifndef _LIBCPP_HAS_NO_VARIADICS
1705 template <class _A0, class _A1, class ..._Args>
1706 __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
1707 #endif // _LIBCPP_HAS_NO_VARIADICS
1708 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1711 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1713 template <class _Key, class _Tp, class _Compare, class _Allocator>
1714 multimap<_Key, _Tp, _Compare, _Allocator>::multimap(multimap&& __m, const allocator_type& __a)
1715 : __tree_(_VSTD::move(__m.__tree_), __a)
1717 if (__a != __m.get_allocator())
1719 const_iterator __e = cend();
1720 while (!__m.empty())
1721 __tree_.__insert_multi(__e.__i_,
1722 _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_));
1726 template <class _Key, class _Tp, class _Compare, class _Allocator>
1727 typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
1728 multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node()
1730 __node_allocator& __na = __tree_.__node_alloc();
1731 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1732 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first));
1733 __h.get_deleter().__first_constructed = true;
1734 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
1735 __h.get_deleter().__second_constructed = true;
1739 template <class _Key, class _Tp, class _Compare, class _Allocator>
1740 template <class _A0>
1741 typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
1742 multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0)
1744 __node_allocator& __na = __tree_.__node_alloc();
1745 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1746 __node_traits::construct(__na, _VSTD::addressof(__h->__value_), _VSTD::forward<_A0>(__a0));
1747 __h.get_deleter().__first_constructed = true;
1748 __h.get_deleter().__second_constructed = true;
1752 #ifndef _LIBCPP_HAS_NO_VARIADICS
1754 template <class _Key, class _Tp, class _Compare, class _Allocator>
1755 template <class _A0, class _A1, class ..._Args>
1756 typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
1757 multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args)
1759 __node_allocator& __na = __tree_.__node_alloc();
1760 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1761 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
1762 _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
1763 _VSTD::forward<_Args>(__args)...);
1764 __h.get_deleter().__first_constructed = true;
1765 __h.get_deleter().__second_constructed = true;
1769 #endif // _LIBCPP_HAS_NO_VARIADICS
1770 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1772 #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1774 template <class _Key, class _Tp, class _Compare, class _Allocator>
1775 template <class ..._Args>
1776 typename multimap<_Key, _Tp, _Compare, _Allocator>::iterator
1777 multimap<_Key, _Tp, _Compare, _Allocator>::emplace(_Args&& ...__args)
1779 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
1780 iterator __r = __tree_.__node_insert_multi(__h.get());
1785 template <class _Key, class _Tp, class _Compare, class _Allocator>
1786 template <class ..._Args>
1787 typename multimap<_Key, _Tp, _Compare, _Allocator>::iterator
1788 multimap<_Key, _Tp, _Compare, _Allocator>::emplace_hint(const_iterator __p,
1791 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
1792 iterator __r = __tree_.__node_insert_multi(__p.__i_, __h.get());
1797 #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1799 template <class _Key, class _Tp, class _Compare, class _Allocator>
1800 inline _LIBCPP_INLINE_VISIBILITY
1802 operator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1803 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
1805 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
1808 template <class _Key, class _Tp, class _Compare, class _Allocator>
1809 inline _LIBCPP_INLINE_VISIBILITY
1811 operator< (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1812 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
1814 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
1817 template <class _Key, class _Tp, class _Compare, class _Allocator>
1818 inline _LIBCPP_INLINE_VISIBILITY
1820 operator!=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1821 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
1823 return !(__x == __y);
1826 template <class _Key, class _Tp, class _Compare, class _Allocator>
1827 inline _LIBCPP_INLINE_VISIBILITY
1829 operator> (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1830 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
1835 template <class _Key, class _Tp, class _Compare, class _Allocator>
1836 inline _LIBCPP_INLINE_VISIBILITY
1838 operator>=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1839 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
1841 return !(__x < __y);
1844 template <class _Key, class _Tp, class _Compare, class _Allocator>
1845 inline _LIBCPP_INLINE_VISIBILITY
1847 operator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1848 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
1850 return !(__y < __x);
1853 template <class _Key, class _Tp, class _Compare, class _Allocator>
1854 inline _LIBCPP_INLINE_VISIBILITY
1856 swap(multimap<_Key, _Tp, _Compare, _Allocator>& __x,
1857 multimap<_Key, _Tp, _Compare, _Allocator>& __y)
1858 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
1863 _LIBCPP_END_NAMESPACE_STD
1865 #endif // _LIBCPP_MAP