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;
67 _Base_ref(
const _Base& __r) : _M_ref(__r) { }
74 typedef _Key key_type;
75 typedef _Tp mapped_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;
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;
96 #if __cplusplus < 201103L 105 map(
const map&) =
default;
106 map(map&&) =
default;
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)) )
126 : _Base(__l, __a) { }
128 template<
typename _InputIterator>
129 map(_InputIterator __first, _InputIterator __last,
130 const allocator_type& __a)
132 __glibcxx_check_valid_constructor_range(__first, __last)),
136 #if __glibcxx_containers_ranges // C++ >= 23 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())
170 __glibcxx_check_valid_constructor_range(__first, __last)),
174 #if __cplusplus >= 201103L 176 operator=(
const map&) =
default;
179 operator=(map&&) =
default;
184 _Base::operator=(__l);
185 this->_M_invalidate_all();
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)
263 auto __res = _Base::emplace(std::forward<_Args>(__args)...);
264 return { { __res.first,
this }, __res.second };
267 template<
typename... _Args>
269 emplace_hint(const_iterator __pos, _Args&&... __args)
274 _Base::emplace_hint(__pos.
base(), std::forward<_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));
295 return { { __res.first,
this }, __res.second };
298 template<
typename _Pair,
typename =
typename 300 _Pair&&>::value>::type>
304 auto __res = _Base::insert(std::forward<_Pair>(__x));
305 return { { __res.first,
this }, __res.second };
309 #if __cplusplus >= 201103L 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 338 _Pair&&>::value>::type>
340 insert(const_iterator __position, _Pair&& __x)
345 _Base::insert(__position.
base(), std::forward<_Pair>(__x)),
351 template<
typename _InputIterator>
353 insert(_InputIterator __first, _InputIterator __last)
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 // C++ >= 17 && HOSTED 367 template <
typename... _Args>
369 try_emplace(
const key_type& __k, _Args&&... __args)
371 auto __res = _Base::try_emplace(__k,
372 std::forward<_Args>(__args)...);
373 return { { __res.first,
this }, __res.second };
376 template <
typename... _Args>
378 try_emplace(key_type&& __k, _Args&&... __args)
380 auto __res = _Base::try_emplace(
std::move(__k),
381 std::forward<_Args>(__args)...);
382 return { { __res.first,
this }, __res.second };
385 # ifdef __glibcxx_associative_heterogeneous_insertion 386 template <__heterogeneous_tree_key<map> _Kt,
typename... _Args>
388 try_emplace(_Kt&& __k, _Args&&... __args)
390 auto __res = _Base::try_emplace(
391 std::forward<_Kt>(__k), std::forward<_Args>(__args)...);
392 return { { __res.first,
this }, __res.second };
396 template <
typename... _Args>
398 try_emplace(const_iterator __hint,
const key_type& __k,
402 auto __it = _Base::try_emplace(__hint.
base(), __k,
403 std::forward<_Args>(__args)...);
404 return { __it,
this };
407 template <
typename... _Args>
409 try_emplace(const_iterator __hint, key_type&& __k, _Args&&... __args)
412 auto __it = _Base::try_emplace(__hint.
base(),
std::move(__k),
413 std::forward<_Args>(__args)...);
414 return { __it,
this };
417 # ifdef __glibcxx_associative_heterogeneous_insertion 418 template <__heterogeneous_tree_key<map> _Kt,
typename... _Args>
420 try_emplace(const_iterator __hint, _Kt&& __k, _Args&&... __args)
423 auto __it = _Base::try_emplace(__hint.
base(),
424 std::forward<_Kt>(__k), std::forward<_Args>(__args)...);
425 return { __it,
this };
429 template <
typename _Obj>
431 insert_or_assign(
const key_type& __k, _Obj&& __obj)
433 auto __res = _Base::insert_or_assign(__k,
434 std::forward<_Obj>(__obj));
435 return { { __res.first,
this }, __res.second };
438 template <
typename _Obj>
440 insert_or_assign(key_type&& __k, _Obj&& __obj)
442 auto __res = _Base::insert_or_assign(
std::move(__k),
443 std::forward<_Obj>(__obj));
444 return { { __res.first,
this }, __res.second };
447 # ifdef __glibcxx_associative_heterogeneous_insertion 448 template <__heterogeneous_tree_key<map> _Kt,
typename _Obj>
450 insert_or_assign(_Kt&& __k, _Obj&& __obj)
452 auto __res = _Base::insert_or_assign(
453 std::forward<_Kt>(__k), std::forward<_Obj>(__obj));
454 return { { __res.first,
this }, __res.second };
458 template <
typename _Obj>
460 insert_or_assign(const_iterator __hint,
461 const key_type& __k, _Obj&& __obj)
464 auto __it = _Base::insert_or_assign(__hint.
base(), __k,
465 std::forward<_Obj>(__obj));
466 return { __it,
this };
469 template <
typename _Obj>
471 insert_or_assign(const_iterator __hint, key_type&& __k, _Obj&& __obj)
474 auto __it = _Base::insert_or_assign(__hint.
base(),
std::move(__k),
475 std::forward<_Obj>(__obj));
476 return { __it,
this };
479 # ifdef __glibcxx_associative_heterogeneous_insertion 480 template <__heterogeneous_tree_key<map> _Kt,
typename _Obj>
482 insert_or_assign(const_iterator __hint, _Kt&& __k, _Obj&& __obj)
485 auto __it = _Base::insert_or_assign(__hint.
base(),
486 std::forward<_Kt>(__k), std::forward<_Obj>(__obj));
487 return { __it,
this };
493 #ifdef __glibcxx_node_extract // >= C++17 && HOSTED 494 using node_type =
typename _Base::node_type;
498 extract(const_iterator __position)
502 return _Base::extract(__position.
base());
506 extract(
const key_type& __key)
508 const auto __position = find(__key);
509 if (__position != end())
510 return extract(__position);
514 # ifdef __glibcxx_associative_heterogeneous_erasure 515 template <__heterogeneous_tree_key<map> _Kt>
519 const auto __position = find(__key);
520 if (__position != end())
521 return extract(__position);
527 insert(node_type&& __nh)
529 auto __ret = _Base::insert(
std::move(__nh));
531 { { __ret.position,
this }, __ret.inserted,
std::move(__ret.node) };
535 insert(const_iterator __hint, node_type&& __nh)
538 return { _Base::insert(__hint.
base(),
std::move(__nh)),
this };
544 #if __cplusplus >= 201103L 546 erase(const_iterator __position)
549 return { erase(__position.
base()),
this };
553 erase(_Base_const_iterator __position)
555 __glibcxx_check_erase2(__position);
557 return _Base::erase(__position);
560 _GLIBCXX_ABI_TAG_CXX11
562 erase(iterator __position)
563 {
return erase(const_iterator(__position)); }
566 erase(iterator __position)
570 _Base::erase(__position.
base());
575 erase(
const key_type& __x)
577 _Base_iterator __victim = _Base::find(__x);
578 if (__victim == _Base::end())
583 _Base::erase(__victim);
588 # ifdef __glibcxx_associative_heterogeneous_erasure 592 template <__heterogeneous_tree_key<map> _Kt>
596 auto __victims = _Base::equal_range(__x);
597 size_type __count = 0;
598 for (
auto __victim = __victims.first; __victim != __victims.second;)
601 _Base::erase(__victim++);
608 #if __cplusplus >= 201103L 610 erase(const_iterator __first, const_iterator __last)
615 for (_Base_const_iterator __victim = __first.
base();
616 __victim != __last.
base(); ++__victim)
618 _GLIBCXX_DEBUG_VERIFY(__victim != _Base::cend(),
619 _M_message(__gnu_debug::__msg_valid_range)
620 ._M_iterator(__first,
"first")
621 ._M_iterator(__last,
"last"));
625 return { _Base::erase(__first.
base(), __last.
base()),
this };
629 erase(iterator __first, iterator __last)
634 for (_Base_iterator __victim = __first.
base();
635 __victim != __last.
base(); ++__victim)
637 _GLIBCXX_DEBUG_VERIFY(__victim != _Base::end(),
638 _M_message(__gnu_debug::__msg_valid_range)
639 ._M_iterator(__first,
"first")
640 ._M_iterator(__last,
"last"));
643 _Base::erase(__first.
base(), __last.
base());
649 _GLIBCXX_NOEXCEPT_IF( noexcept(declval<_Base&>().swap(__x)) )
656 clear() _GLIBCXX_NOEXCEPT
658 this->_M_invalidate_all();
663 using _Base::key_comp;
664 using _Base::value_comp;
668 find(
const key_type& __x)
669 {
return iterator(_Base::find(__x),
this); }
671 #ifdef __glibcxx_generic_associative_lookup // C++ >= 14 672 template<
typename _Kt,
674 typename __has_is_transparent<_Compare, _Kt>::type>
677 {
return { _Base::find(__x),
this }; }
681 find(
const key_type& __x)
const 682 {
return const_iterator(_Base::find(__x),
this); }
684 #ifdef __glibcxx_generic_associative_lookup // C++ >= 14 685 template<
typename _Kt,
687 typename __has_is_transparent<_Compare, _Kt>::type>
689 find(
const _Kt& __x)
const 690 {
return { _Base::find(__x),
this }; }
696 lower_bound(
const key_type& __x)
697 {
return iterator(_Base::lower_bound(__x),
this); }
699 #ifdef __glibcxx_generic_associative_lookup // C++ >= 14 700 template<
typename _Kt,
702 typename __has_is_transparent<_Compare, _Kt>::type>
704 lower_bound(
const _Kt& __x)
705 {
return { _Base::lower_bound(__x),
this }; }
709 lower_bound(
const key_type& __x)
const 710 {
return const_iterator(_Base::lower_bound(__x),
this); }
712 #ifdef __glibcxx_generic_associative_lookup // C++ >= 14 713 template<
typename _Kt,
715 typename __has_is_transparent<_Compare, _Kt>::type>
717 lower_bound(
const _Kt& __x)
const 718 {
return { _Base::lower_bound(__x),
this }; }
722 upper_bound(
const key_type& __x)
723 {
return iterator(_Base::upper_bound(__x),
this); }
725 #ifdef __glibcxx_generic_associative_lookup // C++ >= 14 726 template<
typename _Kt,
728 typename __has_is_transparent<_Compare, _Kt>::type>
730 upper_bound(
const _Kt& __x)
731 {
return { _Base::upper_bound(__x),
this }; }
735 upper_bound(
const key_type& __x)
const 736 {
return const_iterator(_Base::upper_bound(__x),
this); }
738 #ifdef __glibcxx_generic_associative_lookup // C++ >= 14 739 template<
typename _Kt,
741 typename __has_is_transparent<_Compare, _Kt>::type>
743 upper_bound(
const _Kt& __x)
const 744 {
return { _Base::upper_bound(__x),
this }; }
748 equal_range(
const key_type& __x)
751 _Base::equal_range(__x);
752 return std::make_pair(iterator(__res.
first,
this),
753 iterator(__res.
second,
this));
756 #ifdef __glibcxx_generic_associative_lookup // C++ >= 14 757 template<
typename _Kt,
759 typename __has_is_transparent<_Compare, _Kt>::type>
761 equal_range(
const _Kt& __x)
763 auto __res = _Base::equal_range(__x);
764 return { { __res.first,
this }, { __res.second,
this } };
769 equal_range(
const key_type& __x)
const 772 _Base::equal_range(__x);
773 return std::make_pair(const_iterator(__res.
first,
this),
774 const_iterator(__res.
second,
this));
777 #ifdef __glibcxx_generic_associative_lookup // C++ >= 14 778 template<
typename _Kt,
780 typename __has_is_transparent<_Compare, _Kt>::type>
782 equal_range(
const _Kt& __x)
const 784 auto __res = _Base::equal_range(__x);
785 return { { __res.first,
this }, { __res.second,
this } };
790 _M_base() _GLIBCXX_NOEXCEPT {
return *
this; }
793 _M_base()
const _GLIBCXX_NOEXCEPT {
return *
this; }
796 #if __cpp_deduction_guides >= 201606 798 template<
typename _InputIterator,
801 typename = _RequireInputIter<_InputIterator>,
802 typename = _RequireNotAllocator<_Compare>,
803 typename = _RequireAllocator<_Allocator>>
804 map(_InputIterator, _InputIterator,
805 _Compare = _Compare(), _Allocator = _Allocator())
807 _Compare, _Allocator>;
809 template<
typename _Key,
typename _Tp,
typename _Compare = less<_Key>,
810 typename _Allocator = allocator<pair<const _Key, _Tp>>,
811 typename = _RequireNotAllocator<_Compare>,
812 typename = _RequireAllocator<_Allocator>>
814 _Compare = _Compare(), _Allocator = _Allocator())
817 template <
typename _InputIterator,
typename _Allocator,
818 typename = _RequireInputIter<_InputIterator>,
819 typename = _RequireAllocator<_Allocator>>
820 map(_InputIterator, _InputIterator, _Allocator)
824 template<
typename _Key,
typename _Tp,
typename _Allocator,
825 typename = _RequireAllocator<_Allocator>>
829 #if __glibcxx_containers_ranges // C++ >= 23 830 template<ranges::input_range _Rg,
832 __allocator_like _Alloc =
834 map(from_range_t, _Rg&&, _Compare = _Compare(), _Alloc = _Alloc())
836 __detail::__range_mapped_type<_Rg>,
839 template<ranges::input_range _Rg, __allocator_like _Alloc>
840 map(from_range_t, _Rg&&, _Alloc)
842 __detail::__range_mapped_type<_Rg>,
846 #endif // deduction guides 848 template<
typename _Key,
typename _Tp,
849 typename _Compare,
typename _Allocator>
853 {
return __lhs._M_base() == __rhs._M_base(); }
855 #if __cpp_lib_three_way_comparison 856 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
857 inline __detail::__synth3way_t<pair<const _Key, _Tp>>
860 {
return __lhs._M_base() <=> __rhs._M_base(); }
862 template<
typename _Key,
typename _Tp,
863 typename _Compare,
typename _Allocator>
867 {
return __lhs._M_base() != __rhs._M_base(); }
869 template<
typename _Key,
typename _Tp,
870 typename _Compare,
typename _Allocator>
872 operator<(const map<_Key, _Tp, _Compare, _Allocator>& __lhs,
874 {
return __lhs._M_base() < __rhs._M_base(); }
876 template<
typename _Key,
typename _Tp,
877 typename _Compare,
typename _Allocator>
879 operator<=(const map<_Key, _Tp, _Compare, _Allocator>& __lhs,
881 {
return __lhs._M_base() <= __rhs._M_base(); }
883 template<
typename _Key,
typename _Tp,
884 typename _Compare,
typename _Allocator>
888 {
return __lhs._M_base() >= __rhs._M_base(); }
890 template<
typename _Key,
typename _Tp,
891 typename _Compare,
typename _Allocator>
895 {
return __lhs._M_base() > __rhs._M_base(); }
896 #endif // three-way comparison 898 template<
typename _Key,
typename _Tp,
899 typename _Compare,
typename _Allocator>
903 _GLIBCXX_NOEXCEPT_IF(noexcept(__lhs.swap(__rhs)))
904 { __lhs.swap(__rhs); }
#define __glibcxx_check_erase_range(_First, _Last)
#define __glibcxx_check_erase(_Position)
One of the comparison functors.
#define __glibcxx_check_insert(_Position)
ISO C++ entities toplevel namespace is std.
Class std::map with safety/checking/debug instrumentation.
Struct holding two objects of arbitrary type.
Safe class dealing with some allocator dependent operations.
Return type of insert(node_handle&&) on unique maps/sets.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
Define a member typedef type only if a boolean constant is true.
constexpr _Iterator & base() noexcept
Return the underlying iterator.
Like _Safe_sequence but with a special _M_invalidate_all implementation not invalidating past-the-end...
The standard allocator, as per C++03 [20.4.1].
_T2 second
The second member.
_T1 first
The first member.
constexpr _Iterator __base(_Iterator __it)
constexpr void _M_invalidate_if(_Predicate __pred) const