29 #ifndef _GLIBCXX_DEBUG_MAP_H
30 #define _GLIBCXX_DEBUG_MAP_H 1
37 namespace 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> > >
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;
59 template<
typename _ItT,
typename _SeqT,
typename _CatT>
60 friend class ::__gnu_debug::_Safe_iterator;
64 typedef _Key key_type;
65 typedef _Tp mapped_type;
67 typedef _Compare key_compare;
68 typedef _Allocator allocator_type;
69 typedef typename _Base::reference reference;
70 typedef typename _Base::const_reference const_reference;
77 typedef typename _Base::size_type size_type;
78 typedef typename _Base::difference_type difference_type;
79 typedef typename _Base::pointer pointer;
80 typedef typename _Base::const_pointer const_pointer;
86 #if __cplusplus < 201103L
99 const _Compare& __c = _Compare(),
100 const allocator_type& __a = allocator_type())
101 :
_Base(__l, __c, __a) { }
104 map(
const allocator_type& __a)
107 map(
const map& __m,
const allocator_type& __a)
108 :
_Base(__m, __a) { }
110 map(
map&& __m,
const allocator_type& __a)
116 :
_Base(__l, __a) { }
118 template<
typename _InputIterator>
119 map(_InputIterator __first, _InputIterator __last,
120 const allocator_type& __a)
122 __glibcxx_check_valid_constructor_range(__first, __last)),
132 explicit map(
const _Compare& __comp,
133 const _Allocator& __a = _Allocator())
134 :
_Base(__comp, __a) { }
136 template<
typename _InputIterator>
137 map(_InputIterator __first, _InputIterator __last,
138 const _Compare& __comp = _Compare(),
139 const _Allocator& __a = _Allocator())
141 __glibcxx_check_valid_constructor_range(__first, __last)),
145 #if __cplusplus < 201103L
147 operator=(
const map& __x)
149 this->_M_safe() = __x;
155 operator=(
const map&) =
default;
158 operator=(
map&&) =
default;
164 this->_M_invalidate_all();
171 using _Base::get_allocator;
175 begin() _GLIBCXX_NOEXCEPT
176 {
return iterator(_Base::begin(),
this); }
179 begin()
const _GLIBCXX_NOEXCEPT
183 end() _GLIBCXX_NOEXCEPT
184 {
return iterator(_Base::end(),
this); }
187 end()
const _GLIBCXX_NOEXCEPT
191 rbegin() _GLIBCXX_NOEXCEPT
195 rbegin()
const _GLIBCXX_NOEXCEPT
199 rend() _GLIBCXX_NOEXCEPT
203 rend()
const _GLIBCXX_NOEXCEPT
206 #if __cplusplus >= 201103L
208 cbegin()
const noexcept
212 cend()
const noexcept
216 crbegin()
const noexcept
220 crend()
const noexcept
227 using _Base::max_size;
230 using _Base::operator[];
237 #if __cplusplus >= 201103L
238 template<
typename... _Args>
240 emplace(_Args&&... __args)
242 auto __res = _Base::emplace(std::forward<_Args>(__args)...);
243 return { { __res.first,
this }, __res.second };
246 template<
typename... _Args>
253 _Base::emplace_hint(__pos.
base(), std::forward<_Args>(__args)...),
267 #if __cplusplus >= 201103L
273 auto __res = _Base::insert(
std::move(__x));
274 return { { __res.first,
this }, __res.second };
277 template<
typename _Pair,
typename =
typename
279 _Pair&&>::value>::type>
283 auto __res = _Base::insert(std::forward<_Pair>(__x));
284 return { { __res.first,
this }, __res.second };
288 #if __cplusplus >= 201103L
291 { _Base::insert(__list); }
295 #if __cplusplus >= 201103L
302 return iterator(_Base::insert(__position.
base(), __x),
this);
305 #if __cplusplus >= 201103L
312 return { _Base::insert(__position.
base(),
std::move(__x)),
this };
315 template<
typename _Pair,
typename =
typename
317 _Pair&&>::value>::type>
324 _Base::insert(__position.
base(), std::forward<_Pair>(__x)),
330 template<
typename _InputIterator>
332 insert(_InputIterator __first, _InputIterator __last)
335 __glibcxx_check_valid_range2(__first, __last, __dist);
337 if (__dist.
second >= __gnu_debug::__dp_sign)
338 _Base::insert(__gnu_debug::__unsafe(__first),
339 __gnu_debug::__unsafe(__last));
341 _Base::insert(__first, __last);
345 #if __cplusplus > 201402L
346 template <
typename... _Args>
348 try_emplace(
const key_type& __k, _Args&&... __args)
350 auto __res = _Base::try_emplace(__k,
351 std::forward<_Args>(__args)...);
352 return { { __res.first,
this }, __res.second };
355 template <
typename... _Args>
357 try_emplace(key_type&& __k, _Args&&... __args)
359 auto __res = _Base::try_emplace(
std::move(__k),
360 std::forward<_Args>(__args)...);
361 return { { __res.first,
this }, __res.second };
364 template <
typename... _Args>
372 _Base::try_emplace(__hint.
base(), __k,
373 std::forward<_Args>(__args)...),
378 template <
typename... _Args>
380 try_emplace(
const_iterator __hint, key_type&& __k, _Args&&... __args)
386 std::forward<_Args>(__args)...),
391 template <
typename _Obj>
393 insert_or_assign(
const key_type& __k, _Obj&& __obj)
395 auto __res = _Base::insert_or_assign(__k,
396 std::forward<_Obj>(__obj));
397 return { { __res.first,
this }, __res.second };
400 template <
typename _Obj>
402 insert_or_assign(key_type&& __k, _Obj&& __obj)
404 auto __res = _Base::insert_or_assign(
std::move(__k),
405 std::forward<_Obj>(__obj));
406 return { { __res.first,
this }, __res.second };
409 template <
typename _Obj>
412 const key_type& __k, _Obj&& __obj)
417 _Base::insert_or_assign(__hint.
base(), __k,
418 std::forward<_Obj>(__obj)),
423 template <
typename _Obj>
425 insert_or_assign(
const_iterator __hint, key_type&& __k, _Obj&& __obj)
431 std::forward<_Obj>(__obj)),
437 #if __cplusplus > 201402L
438 using node_type =
typename _Base::node_type;
439 using insert_return_type = _Node_insert_return<iterator, node_type>;
446 return _Base::extract(__position.
base());
450 extract(
const key_type& __key)
452 const auto __position = find(__key);
453 if (__position != end())
454 return extract(__position);
459 insert(node_type&& __nh)
461 auto __ret = _Base::insert(
std::move(__nh));
463 { { __ret.position,
this }, __ret.inserted,
std::move(__ret.node) };
470 return { _Base::insert(__hint.
base(),
std::move(__nh)),
this };
476 #if __cplusplus >= 201103L
482 return { _Base::erase(__position.
base()),
this };
485 _GLIBCXX_ABI_TAG_CXX11
495 _Base::erase(__position.
base());
500 erase(
const key_type& __x)
503 if (__victim == _Base::end())
508 _Base::erase(__victim);
513 #if __cplusplus >= 201103L
521 __victim != __last.
base(); ++__victim)
523 _GLIBCXX_DEBUG_VERIFY(__victim != _Base::cend(),
524 _M_message(__gnu_debug::__msg_valid_range)
525 ._M_iterator(__first,
"first")
526 ._M_iterator(__last,
"last"));
530 return { _Base::erase(__first.base(), __last.
base()),
this };
540 __victim != __last.
base(); ++__victim)
542 _GLIBCXX_DEBUG_VERIFY(__victim != _Base::end(),
543 _M_message(__gnu_debug::__msg_valid_range)
544 ._M_iterator(__first,
"first")
545 ._M_iterator(__last,
"last"));
548 _Base::erase(__first.base(), __last.
base());
554 _GLIBCXX_NOEXCEPT_IF( noexcept(declval<_Base&>().swap(__x)) )
561 clear() _GLIBCXX_NOEXCEPT
563 this->_M_invalidate_all();
568 using _Base::key_comp;
569 using _Base::value_comp;
573 find(
const key_type& __x)
574 {
return iterator(_Base::find(__x),
this); }
576 #if __cplusplus > 201103L
577 template<
typename _Kt,
579 typename __has_is_transparent<_Compare, _Kt>::type>
582 {
return { _Base::find(__x),
this }; }
586 find(
const key_type& __x)
const
589 #if __cplusplus > 201103L
590 template<
typename _Kt,
592 typename __has_is_transparent<_Compare, _Kt>::type>
594 find(
const _Kt& __x)
const
595 {
return { _Base::find(__x),
this }; }
601 lower_bound(
const key_type& __x)
602 {
return iterator(_Base::lower_bound(__x),
this); }
604 #if __cplusplus > 201103L
605 template<
typename _Kt,
607 typename __has_is_transparent<_Compare, _Kt>::type>
609 lower_bound(
const _Kt& __x)
610 {
return { _Base::lower_bound(__x),
this }; }
614 lower_bound(
const key_type& __x)
const
617 #if __cplusplus > 201103L
618 template<
typename _Kt,
620 typename __has_is_transparent<_Compare, _Kt>::type>
622 lower_bound(
const _Kt& __x)
const
623 {
return { _Base::lower_bound(__x),
this }; }
627 upper_bound(
const key_type& __x)
628 {
return iterator(_Base::upper_bound(__x),
this); }
630 #if __cplusplus > 201103L
631 template<
typename _Kt,
633 typename __has_is_transparent<_Compare, _Kt>::type>
635 upper_bound(
const _Kt& __x)
636 {
return { _Base::upper_bound(__x),
this }; }
640 upper_bound(
const key_type& __x)
const
643 #if __cplusplus > 201103L
644 template<
typename _Kt,
646 typename __has_is_transparent<_Compare, _Kt>::type>
648 upper_bound(
const _Kt& __x)
const
649 {
return { _Base::upper_bound(__x),
this }; }
653 equal_range(
const key_type& __x)
656 _Base::equal_range(__x);
661 #if __cplusplus > 201103L
662 template<
typename _Kt,
664 typename __has_is_transparent<_Compare, _Kt>::type>
666 equal_range(
const _Kt& __x)
668 auto __res = _Base::equal_range(__x);
669 return { { __res.first,
this }, { __res.second,
this } };
674 equal_range(
const key_type& __x)
const
677 _Base::equal_range(__x);
682 #if __cplusplus > 201103L
683 template<
typename _Kt,
685 typename __has_is_transparent<_Compare, _Kt>::type>
687 equal_range(
const _Kt& __x)
const
689 auto __res = _Base::equal_range(__x);
690 return { { __res.first,
this }, { __res.second,
this } };
695 _M_base() _GLIBCXX_NOEXCEPT {
return *
this; }
698 _M_base()
const _GLIBCXX_NOEXCEPT {
return *
this; }
701 #if __cpp_deduction_guides >= 201606
703 template<
typename _InputIterator,
706 typename = _RequireInputIter<_InputIterator>,
707 typename = _RequireNotAllocator<_Compare>,
708 typename = _RequireAllocator<_Allocator>>
709 map(_InputIterator, _InputIterator,
710 _Compare = _Compare(), _Allocator = _Allocator())
712 _Compare, _Allocator>;
714 template<
typename _Key,
typename _Tp,
typename _Compare = less<_Key>,
715 typename _Allocator = allocator<pair<const _Key, _Tp>>,
716 typename = _RequireNotAllocator<_Compare>,
717 typename = _RequireAllocator<_Allocator>>
719 _Compare = _Compare(), _Allocator = _Allocator())
722 template <
typename _InputIterator,
typename _Allocator,
723 typename = _RequireInputIter<_InputIterator>,
724 typename = _RequireAllocator<_Allocator>>
725 map(_InputIterator, _InputIterator, _Allocator)
729 template<
typename _Key,
typename _Tp,
typename _Allocator,
730 typename = _RequireAllocator<_Allocator>>
736 template<
typename _Key,
typename _Tp,
737 typename _Compare,
typename _Allocator>
741 {
return __lhs._M_base() == __rhs._M_base(); }
743 #if __cpp_lib_three_way_comparison
744 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
745 inline __detail::__synth3way_t<pair<const _Key, _Tp>>
748 {
return __lhs._M_base() <=> __rhs._M_base(); }
750 template<
typename _Key,
typename _Tp,
751 typename _Compare,
typename _Allocator>
753 operator!=(
const map<_Key, _Tp, _Compare, _Allocator>& __lhs,
754 const map<_Key, _Tp, _Compare, _Allocator>& __rhs)
755 {
return __lhs._M_base() != __rhs._M_base(); }
757 template<
typename _Key,
typename _Tp,
758 typename _Compare,
typename _Allocator>
760 operator<(
const map<_Key, _Tp, _Compare, _Allocator>& __lhs,
761 const map<_Key, _Tp, _Compare, _Allocator>& __rhs)
762 {
return __lhs._M_base() < __rhs._M_base(); }
764 template<
typename _Key,
typename _Tp,
765 typename _Compare,
typename _Allocator>
767 operator<=(
const map<_Key, _Tp, _Compare, _Allocator>& __lhs,
768 const map<_Key, _Tp, _Compare, _Allocator>& __rhs)
769 {
return __lhs._M_base() <= __rhs._M_base(); }
771 template<
typename _Key,
typename _Tp,
772 typename _Compare,
typename _Allocator>
774 operator>=(
const map<_Key, _Tp, _Compare, _Allocator>& __lhs,
775 const map<_Key, _Tp, _Compare, _Allocator>& __rhs)
776 {
return __lhs._M_base() >= __rhs._M_base(); }
778 template<
typename _Key,
typename _Tp,
779 typename _Compare,
typename _Allocator>
781 operator>(
const map<_Key, _Tp, _Compare, _Allocator>& __lhs,
782 const map<_Key, _Tp, _Compare, _Allocator>& __rhs)
783 {
return __lhs._M_base() > __rhs._M_base(); }
786 template<
typename _Key,
typename _Tp,
787 typename _Compare,
typename _Allocator>
789 swap(map<_Key, _Tp, _Compare, _Allocator>& __lhs,
790 map<_Key, _Tp, _Compare, _Allocator>& __rhs)
791 _GLIBCXX_NOEXCEPT_IF(noexcept(__lhs.swap(__rhs)))
792 { __lhs.swap(__rhs); }
#define __glibcxx_check_insert(_Position)
#define __glibcxx_check_erase_range(_First, _Last)
#define __glibcxx_check_erase(_Position)
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
ISO C++ entities toplevel namespace is std.
constexpr _Iterator __base(_Iterator __it)
Define a member typedef type only if a boolean constant is true.
The standard allocator, as per C++03 [20.4.1].
One of the comparison functors.
A standard container made up of (key,value) pairs, which can be retrieved based on a key,...
Struct holding two objects of arbitrary type.
_T1 first
The first member.
_T2 second
The second member.
_Iterator & base() noexcept
Return the underlying iterator.
void _M_invalidate_if(_Predicate __pred)
Class std::map with safety/checking/debug instrumentation.
Safe class dealing with some allocator dependent operations.
Like _Safe_sequence but with a special _M_invalidate_all implementation not invalidating past-the-end...