29#ifndef _GLIBCXX_DEBUG_MAP_H
30#define _GLIBCXX_DEBUG_MAP_H 1
37namespace std _GLIBCXX_VISIBILITY(default)
42 template<
typename _Key,
typename _Tp,
typename _Compare = std::less<_Key>,
43 typename _Allocator = std::allocator<std::pair<const _Key, _Tp> > >
45 :
public __gnu_debug::_Safe_container<
46 map<_Key, _Tp, _Compare, _Allocator>, _Allocator,
47 __gnu_debug::_Safe_node_sequence>,
48 public _GLIBCXX_STD_C::map<_Key, _Tp, _Compare, _Allocator>
50 typedef _GLIBCXX_STD_C::map<
51 _Key, _Tp, _Compare, _Allocator> _Base;
52 typedef __gnu_debug::_Safe_container<
53 map, _Allocator, __gnu_debug::_Safe_node_sequence> _Safe;
55 typedef typename _Base::const_iterator _Base_const_iterator;
56 typedef typename _Base::iterator _Base_iterator;
57 typedef __gnu_debug::_Equal_to<_Base_const_iterator> _Equal;
59 template<
typename _ItT,
typename _SeqT,
typename _CatT>
60 friend class ::__gnu_debug::_Safe_iterator;
67 _Base_ref(
const _Base& __r) : _M_ref(__r) { }
74 typedef _Key key_type;
75 typedef _Tp mapped_type;
76 typedef std::pair<const _Key, _Tp> value_type;
77 typedef _Compare key_compare;
78 typedef _Allocator allocator_type;
79 typedef typename _Base::reference reference;
80 typedef typename _Base::const_reference const_reference;
82 typedef __gnu_debug::_Safe_iterator<_Base_iterator, map>
84 typedef __gnu_debug::_Safe_iterator<_Base_const_iterator, map>
87 typedef typename _Base::size_type size_type;
88 typedef typename _Base::difference_type difference_type;
89 typedef typename _Base::pointer pointer;
90 typedef typename _Base::const_pointer const_pointer;
91 typedef std::reverse_iterator<iterator> reverse_iterator;
92 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
96#if __cplusplus < 201103L
105 map(
const map&) =
default;
106 map(map&&) =
default;
108 map(initializer_list<value_type> __l,
109 const _Compare& __c = _Compare(),
110 const allocator_type& __a = allocator_type())
111 : _Base(__l, __c, __a) { }
114 map(
const allocator_type& __a)
117 map(
const map& __m,
const __type_identity_t<allocator_type>& __a)
118 : _Base(__m, __a) { }
120 map(map&& __m,
const __type_identity_t<allocator_type>& __a)
121 noexcept(
noexcept(_Base(
std::move(__m), __a)) )
122 : _Safe(std::
move(__m), __a),
123 _Base(std::
move(__m), __a) { }
125 map(initializer_list<value_type> __l,
const allocator_type& __a)
126 : _Base(__l, __a) { }
128 template<
typename _InputIterator>
129 map(_InputIterator __first, _InputIterator __last,
130 const allocator_type& __a)
131 : _Base(__gnu_debug::
__base(
132 __glibcxx_check_valid_constructor_range(__first, __last)),
133 __gnu_debug::
__base(__last), __a)
136#if __glibcxx_containers_ranges
141 template<std::__detail::__container_compatible_range<value_type> _Rg>
142 map(std::from_range_t __t, _Rg&& __rg,
144 const allocator_type& __a = allocator_type())
145 : _Base(__t, std::
forward<_Rg>(__rg), __c, __a)
148 template<std::__detail::__container_compatible_range<value_type> _Rg>
149 map(std::from_range_t __t, _Rg&& __rg,
150 const allocator_type& __a = allocator_type())
151 : _Base(__t, std::
forward<_Rg>(__rg), __a)
159 : _Base(__x._M_ref) { }
161 explicit map(
const _Compare& __comp,
162 const _Allocator& __a = _Allocator())
163 : _Base(__comp, __a) { }
165 template<
typename _InputIterator>
166 map(_InputIterator __first, _InputIterator __last,
167 const _Compare& __comp = _Compare(),
168 const _Allocator& __a = _Allocator())
169 : _Base(__gnu_debug::
__base(
170 __glibcxx_check_valid_constructor_range(__first, __last)),
171 __gnu_debug::
__base(__last),
174#if __cplusplus >= 201103L
176 operator=(
const map&) =
default;
179 operator=(map&&) =
default;
182 operator=(initializer_list<value_type> __l)
184 _Base::operator=(__l);
192 using _Base::get_allocator;
196 begin() _GLIBCXX_NOEXCEPT
197 {
return iterator(_Base::begin(),
this); }
200 begin() const _GLIBCXX_NOEXCEPT
201 {
return const_iterator(_Base::begin(),
this); }
204 end() _GLIBCXX_NOEXCEPT
205 {
return iterator(_Base::end(),
this); }
208 end() const _GLIBCXX_NOEXCEPT
209 {
return const_iterator(_Base::end(),
this); }
212 rbegin() _GLIBCXX_NOEXCEPT
213 {
return reverse_iterator(end()); }
215 const_reverse_iterator
216 rbegin() const _GLIBCXX_NOEXCEPT
217 {
return const_reverse_iterator(end()); }
220 rend() _GLIBCXX_NOEXCEPT
221 {
return reverse_iterator(begin()); }
223 const_reverse_iterator
224 rend() const _GLIBCXX_NOEXCEPT
225 {
return const_reverse_iterator(begin()); }
227#if __cplusplus >= 201103L
229 cbegin() const noexcept
230 {
return const_iterator(_Base::begin(),
this); }
233 cend() const noexcept
234 {
return const_iterator(_Base::end(),
this); }
236 const_reverse_iterator
237 crbegin() const noexcept
238 {
return const_reverse_iterator(end()); }
240 const_reverse_iterator
241 crend() const noexcept
242 {
return const_reverse_iterator(begin()); }
248 using _Base::max_size;
251 using _Base::operator[];
258#if __cplusplus >= 201103L
259 template<
typename... _Args>
261 emplace(_Args&&... __args)
264 return { { __res.first,
this }, __res.second };
267 template<
typename... _Args>
269 emplace_hint(const_iterator __pos, _Args&&... __args)
281 insert(
const value_type& __x)
288#if __cplusplus >= 201103L
292 insert(value_type&& __x)
294 auto __res = _Base::insert(
std::move(__x));
298 template<
typename _Pair,
typename =
typename
299 std::enable_if<std::is_constructible<value_type,
300 _Pair&&>::value>::type>
309#if __cplusplus >= 201103L
311 insert(std::initializer_list<value_type> __list)
312 { _Base::insert(__list); }
316#if __cplusplus >= 201103L
317 insert(const_iterator __position,
const value_type& __x)
319 insert(iterator __position,
const value_type& __x)
323 return iterator(_Base::insert(__position.base(), __x),
this);
326#if __cplusplus >= 201103L
330 insert(const_iterator __position, value_type&& __x)
333 return { _Base::insert(__position.base(),
std::move(__x)),
this };
336 template<
typename _Pair,
typename =
typename
337 std::enable_if<std::is_constructible<value_type,
338 _Pair&&>::value>::type>
340 insert(const_iterator __position, _Pair&& __x)
351 template<
typename _InputIterator>
353 insert(_InputIterator __first, _InputIterator __last)
355 typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
356 __glibcxx_check_valid_range2(__first, __last, __dist);
358 if (__dist.second >= __gnu_debug::__dp_sign)
359 _Base::insert(__gnu_debug::__unsafe(__first),
360 __gnu_debug::__unsafe(__last));
362 _Base::insert(__first, __last);
366#ifdef __glibcxx_map_try_emplace
367 template <
typename... _Args>
369 try_emplace(
const key_type& __k, _Args&&... __args)
371 auto __res = _Base::try_emplace(__k,
376 template <
typename... _Args>
378 try_emplace(key_type&& __k, _Args&&... __args)
380 auto __res = _Base::try_emplace(
std::move(__k),
385 template <
typename... _Args>
387 try_emplace(const_iterator __hint,
const key_type& __k,
393 _Base::try_emplace(__hint.base(), __k,
399 template <
typename... _Args>
401 try_emplace(const_iterator __hint, key_type&& __k, _Args&&... __args)
406 _Base::try_emplace(__hint.base(),
std::move(__k),
412 template <
typename _Obj>
414 insert_or_assign(
const key_type& __k, _Obj&& __obj)
416 auto __res = _Base::insert_or_assign(__k,
421 template <
typename _Obj>
423 insert_or_assign(key_type&& __k, _Obj&& __obj)
425 auto __res = _Base::insert_or_assign(
std::move(__k),
430 template <
typename _Obj>
432 insert_or_assign(const_iterator __hint,
433 const key_type& __k, _Obj&& __obj)
438 _Base::insert_or_assign(__hint.base(), __k,
444 template <
typename _Obj>
446 insert_or_assign(const_iterator __hint, key_type&& __k, _Obj&& __obj)
451 _Base::insert_or_assign(__hint.base(),
std::move(__k),
458#if __cplusplus > 201402L
459 using node_type =
typename _Base::node_type;
460 using insert_return_type = _Node_insert_return<iterator, node_type>;
463 extract(const_iterator __position)
467 return _Base::extract(__position.base());
471 extract(
const key_type& __key)
473 const auto __position = find(__key);
474 if (__position != end())
475 return extract(__position);
480 insert(node_type&& __nh)
482 auto __ret = _Base::insert(
std::move(__nh));
484 { { __ret.position,
this }, __ret.inserted,
std::move(__ret.node) };
488 insert(const_iterator __hint, node_type&& __nh)
491 return { _Base::insert(__hint.base(),
std::move(__nh)),
this };
497#if __cplusplus >= 201103L
499 erase(const_iterator __position)
502 return { erase(__position.base()),
this };
506 erase(_Base_const_iterator __position)
508 __glibcxx_check_erase2(__position);
510 return _Base::erase(__position);
513 _GLIBCXX_ABI_TAG_CXX11
515 erase(iterator __position)
516 {
return erase(const_iterator(__position)); }
519 erase(iterator __position)
523 _Base::erase(__position.base());
528 erase(
const key_type& __x)
530 _Base_iterator __victim = _Base::find(__x);
531 if (__victim == _Base::end())
536 _Base::erase(__victim);
541#if __cplusplus >= 201103L
543 erase(const_iterator __first, const_iterator __last)
548 for (_Base_const_iterator __victim = __first.base();
549 __victim != __last.base(); ++__victim)
551 _GLIBCXX_DEBUG_VERIFY(__victim != _Base::cend(),
552 _M_message(__gnu_debug::__msg_valid_range)
553 ._M_iterator(__first,
"first")
554 ._M_iterator(__last,
"last"));
558 return { _Base::erase(__first.base(), __last.base()),
this };
562 erase(iterator __first, iterator __last)
567 for (_Base_iterator __victim = __first.base();
568 __victim != __last.base(); ++__victim)
570 _GLIBCXX_DEBUG_VERIFY(__victim != _Base::end(),
571 _M_message(__gnu_debug::__msg_valid_range)
572 ._M_iterator(__first,
"first")
573 ._M_iterator(__last,
"last"));
576 _Base::erase(__first.base(), __last.base());
589 clear() _GLIBCXX_NOEXCEPT
596 using _Base::key_comp;
597 using _Base::value_comp;
601 find(
const key_type& __x)
602 {
return iterator(_Base::find(__x),
this); }
604#if __cplusplus > 201103L
605 template<
typename _Kt,
607 typename __has_is_transparent<_Compare, _Kt>::type>
610 {
return { _Base::find(__x),
this }; }
614 find(
const key_type& __x)
const
615 {
return const_iterator(_Base::find(__x),
this); }
617#if __cplusplus > 201103L
618 template<
typename _Kt,
620 typename __has_is_transparent<_Compare, _Kt>::type>
622 find(
const _Kt& __x)
const
623 {
return { _Base::find(__x),
this }; }
629 lower_bound(
const key_type& __x)
630 {
return iterator(_Base::lower_bound(__x),
this); }
632#if __cplusplus > 201103L
633 template<
typename _Kt,
635 typename __has_is_transparent<_Compare, _Kt>::type>
637 lower_bound(
const _Kt& __x)
638 {
return { _Base::lower_bound(__x),
this }; }
642 lower_bound(
const key_type& __x)
const
643 {
return const_iterator(_Base::lower_bound(__x),
this); }
645#if __cplusplus > 201103L
646 template<
typename _Kt,
648 typename __has_is_transparent<_Compare, _Kt>::type>
650 lower_bound(
const _Kt& __x)
const
651 {
return { _Base::lower_bound(__x),
this }; }
655 upper_bound(
const key_type& __x)
656 {
return iterator(_Base::upper_bound(__x),
this); }
658#if __cplusplus > 201103L
659 template<
typename _Kt,
661 typename __has_is_transparent<_Compare, _Kt>::type>
663 upper_bound(
const _Kt& __x)
664 {
return { _Base::upper_bound(__x),
this }; }
668 upper_bound(
const key_type& __x)
const
669 {
return const_iterator(_Base::upper_bound(__x),
this); }
671#if __cplusplus > 201103L
672 template<
typename _Kt,
674 typename __has_is_transparent<_Compare, _Kt>::type>
676 upper_bound(
const _Kt& __x)
const
677 {
return { _Base::upper_bound(__x),
this }; }
681 equal_range(
const key_type& __x)
684 _Base::equal_range(__x);
686 iterator(__res.
second,
this));
689#if __cplusplus > 201103L
690 template<
typename _Kt,
692 typename __has_is_transparent<_Compare, _Kt>::type>
694 equal_range(
const _Kt& __x)
696 auto __res = _Base::equal_range(__x);
697 return { { __res.
first,
this }, { __res.
second,
this } };
702 equal_range(
const key_type& __x)
const
705 _Base::equal_range(__x);
707 const_iterator(__res.
second,
this));
710#if __cplusplus > 201103L
711 template<
typename _Kt,
713 typename __has_is_transparent<_Compare, _Kt>::type>
715 equal_range(
const _Kt& __x)
const
717 auto __res = _Base::equal_range(__x);
718 return { { __res.
first,
this }, { __res.
second,
this } };
723 _M_base() _GLIBCXX_NOEXCEPT {
return *
this; }
726 _M_base() const _GLIBCXX_NOEXCEPT {
return *
this; }
729#if __cpp_deduction_guides >= 201606
731 template<
typename _InputIterator,
732 typename _Compare = less<__iter_key_t<_InputIterator>>,
733 typename _Allocator = allocator<__iter_to_alloc_t<_InputIterator>>,
734 typename = _RequireInputIter<_InputIterator>,
735 typename = _RequireNotAllocator<_Compare>,
736 typename = _RequireAllocator<_Allocator>>
737 map(_InputIterator, _InputIterator,
738 _Compare = _Compare(), _Allocator = _Allocator())
740 _Compare, _Allocator>;
742 template<
typename _Key,
typename _Tp,
typename _Compare = less<_Key>,
743 typename _Allocator = allocator<pair<const _Key, _Tp>>,
744 typename = _RequireNotAllocator<_Compare>,
745 typename = _RequireAllocator<_Allocator>>
747 _Compare = _Compare(), _Allocator = _Allocator())
750 template <
typename _InputIterator,
typename _Allocator,
751 typename = _RequireInputIter<_InputIterator>,
752 typename = _RequireAllocator<_Allocator>>
753 map(_InputIterator, _InputIterator, _Allocator)
755 less<__iter_key_t<_InputIterator>>, _Allocator>;
757 template<
typename _Key,
typename _Tp,
typename _Allocator,
758 typename = _RequireAllocator<_Allocator>>
762#if __glibcxx_containers_ranges
763 template<ranges::input_range _Rg,
764 __not_allocator_like _Compare = less<__detail::__range_key_type<_Rg>>,
765 __allocator_like _Alloc =
766 std::allocator<__detail::__range_to_alloc_type<_Rg>>>
767 map(from_range_t, _Rg&&, _Compare = _Compare(), _Alloc = _Alloc())
769 __detail::__range_mapped_type<_Rg>,
772 template<ranges::input_range _Rg, __allocator_like _Alloc>
773 map(from_range_t, _Rg&&, _Alloc)
775 __detail::__range_mapped_type<_Rg>,
776 less<__detail::__range_key_type<_Rg>>,
781 template<
typename _Key,
typename _Tp,
782 typename _Compare,
typename _Allocator>
786 {
return __lhs._M_base() == __rhs._M_base(); }
788#if __cpp_lib_three_way_comparison
789 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
790 inline __detail::__synth3way_t<pair<const _Key, _Tp>>
793 {
return __lhs._M_base() <=> __rhs._M_base(); }
795 template<
typename _Key,
typename _Tp,
796 typename _Compare,
typename _Allocator>
800 {
return __lhs._M_base() != __rhs._M_base(); }
802 template<
typename _Key,
typename _Tp,
803 typename _Compare,
typename _Allocator>
807 {
return __lhs._M_base() < __rhs._M_base(); }
809 template<
typename _Key,
typename _Tp,
810 typename _Compare,
typename _Allocator>
814 {
return __lhs._M_base() <= __rhs._M_base(); }
816 template<
typename _Key,
typename _Tp,
817 typename _Compare,
typename _Allocator>
821 {
return __lhs._M_base() >= __rhs._M_base(); }
823 template<
typename _Key,
typename _Tp,
824 typename _Compare,
typename _Allocator>
828 {
return __lhs._M_base() > __rhs._M_base(); }
831 template<
typename _Key,
typename _Tp,
832 typename _Compare,
typename _Allocator>
836 _GLIBCXX_NOEXCEPT_IF(
noexcept(__lhs.swap(__rhs)))
837 { __lhs.swap(__rhs); }
#define __glibcxx_check_insert(_Position)
#define __glibcxx_check_erase_range(_First, _Last)
#define __glibcxx_check_erase(_Position)
constexpr bool operator<=(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
constexpr bool operator>=(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
constexpr bool operator<(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
constexpr bool operator>(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
pair(_T1, _T2) -> pair< _T1, _T2 >
Two pairs are equal iff their members are equal.
constexpr pair< typename __decay_and_strip< _T1 >::__type, typename __decay_and_strip< _T2 >::__type > make_pair(_T1 &&__x, _T2 &&__y)
A convenience wrapper for creating a pair from two objects.
auto declval() noexcept -> decltype(__declval< _Tp >(0))
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
ISO C++ entities toplevel namespace is std.
constexpr _Iterator __base(_Iterator __it)
GNU debug code, replaces standard behavior with debug behavior.
_T1 first
The first member.
_T2 second
The second member.
void _M_invalidate_if(_Predicate __pred)
Class std::map with safety/checking/debug instrumentation.
void _M_invalidate_all() const