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;
61 typedef _Key key_type;
62 typedef _Tp mapped_type;
64 typedef _Compare key_compare;
65 typedef _Allocator allocator_type;
66 typedef typename _Base::reference reference;
67 typedef typename _Base::const_reference const_reference;
74 typedef typename _Base::size_type size_type;
75 typedef typename _Base::difference_type difference_type;
76 typedef typename _Base::pointer pointer;
77 typedef typename _Base::const_pointer const_pointer;
83 #if __cplusplus < 201103L 96 const _Compare& __c = _Compare(),
97 const allocator_type& __a = allocator_type())
98 :
_Base(__l, __c, __a) { }
101 map(
const allocator_type& __a)
104 map(
const map& __m,
const allocator_type& __a)
105 :
_Base(__m, __a) { }
107 map(
map&& __m,
const allocator_type& __a)
108 noexcept( noexcept(
_Base(std::move(__m._M_base()), __a)) )
109 :
_Safe(std::move(__m._M_safe()), __a),
110 _Base(std::move(__m._M_base()), __a) { }
113 :
_Base(__l, __a) { }
115 template<
typename _InputIterator>
116 map(_InputIterator __first, _InputIterator __last,
117 const allocator_type& __a)
118 :
_Base(__gnu_debug::__base(__gnu_debug::__check_valid_range(__first,
120 __gnu_debug::__base(__last), __a)
129 explicit map(
const _Compare& __comp,
130 const _Allocator& __a = _Allocator())
131 :
_Base(__comp, __a) { }
133 template<
typename _InputIterator>
134 map(_InputIterator __first, _InputIterator __last,
135 const _Compare& __comp = _Compare(),
136 const _Allocator& __a = _Allocator())
137 :
_Base(__gnu_debug::__base(__gnu_debug::__check_valid_range(__first,
139 __gnu_debug::__base(__last),
142 #if __cplusplus < 201103L 144 operator=(
const map& __x)
146 this->_M_safe() = __x;
152 operator=(
const map&) =
default;
155 operator=(
map&&) =
default;
161 this->_M_invalidate_all();
168 using _Base::get_allocator;
172 begin() _GLIBCXX_NOEXCEPT
173 {
return iterator(_Base::begin(),
this); }
176 begin()
const _GLIBCXX_NOEXCEPT
180 end() _GLIBCXX_NOEXCEPT
181 {
return iterator(_Base::end(),
this); }
184 end()
const _GLIBCXX_NOEXCEPT
188 rbegin() _GLIBCXX_NOEXCEPT
192 rbegin()
const _GLIBCXX_NOEXCEPT
196 rend() _GLIBCXX_NOEXCEPT
200 rend()
const _GLIBCXX_NOEXCEPT
203 #if __cplusplus >= 201103L 205 cbegin()
const noexcept
209 cend()
const noexcept
213 crbegin()
const noexcept
217 crend()
const noexcept
224 using _Base::max_size;
227 using _Base::operator[];
234 #if __cplusplus >= 201103L 235 template<
typename... _Args>
237 emplace(_Args&&... __args)
239 auto __res = _Base::emplace(std::forward<_Args>(__args)...);
244 template<
typename... _Args>
250 std::forward<_Args>(__args)...),
263 #if __cplusplus >= 201103L 269 auto __res = _Base::insert(std::move(__x));
270 return {
iterator(__res.first,
this), __res.second };
273 template<
typename _Pair,
typename =
typename 275 _Pair&&>::value>::type>
280 = _Base::insert(std::forward<_Pair>(__x));
286 #if __cplusplus >= 201103L 289 { _Base::insert(__list); }
293 #if __cplusplus >= 201103L 300 return iterator(_Base::insert(__position.
base(), __x),
this);
303 #if __cplusplus >= 201103L 310 return { _Base::insert(__position.
base(), std::move(__x)),
this };
313 template<
typename _Pair,
typename =
typename 315 _Pair&&>::value>::type>
321 std::forward<_Pair>(__x)),
this);
325 template<
typename _InputIterator>
327 insert(_InputIterator __first, _InputIterator __last)
330 __glibcxx_check_valid_range2(__first, __last, __dist);
332 if (__dist.
second >= __gnu_debug::__dp_sign)
333 _Base::insert(__gnu_debug::__unsafe(__first),
334 __gnu_debug::__unsafe(__last));
336 _Base::insert(__first, __last);
340 #if __cplusplus > 201402L 341 template <
typename... _Args>
343 try_emplace(
const key_type& __k, _Args&&... __args)
345 auto __res = _Base::try_emplace(__k,
346 std::forward<_Args>(__args)...);
347 return {
iterator(__res.first,
this), __res.second };
350 template <
typename... _Args>
352 try_emplace(key_type&& __k, _Args&&... __args)
354 auto __res = _Base::try_emplace(std::move(__k),
355 std::forward<_Args>(__args)...);
356 return {
iterator(__res.first,
this), __res.second };
359 template <
typename... _Args>
366 std::forward<_Args>(__args)...),
370 template <
typename... _Args>
372 try_emplace(
const_iterator __hint, key_type&& __k, _Args&&... __args)
375 return iterator(_Base::try_emplace(__hint.
base(), std::move(__k),
376 std::forward<_Args>(__args)...),
380 template <
typename _Obj>
382 insert_or_assign(
const key_type& __k, _Obj&& __obj)
384 auto __res = _Base::insert_or_assign(__k,
385 std::forward<_Obj>(__obj));
386 return {
iterator(__res.first,
this), __res.second };
389 template <
typename _Obj>
391 insert_or_assign(key_type&& __k, _Obj&& __obj)
393 auto __res = _Base::insert_or_assign(std::move(__k),
394 std::forward<_Obj>(__obj));
395 return {
iterator(__res.first,
this), __res.second };
398 template <
typename _Obj>
401 const key_type& __k, _Obj&& __obj)
404 return iterator(_Base::insert_or_assign(__hint.
base(), __k,
405 std::forward<_Obj>(__obj)),
409 template <
typename _Obj>
411 insert_or_assign(
const_iterator __hint, key_type&& __k, _Obj&& __obj)
416 std::forward<_Obj>(__obj)),
421 #if __cplusplus > 201402L 422 using node_type =
typename _Base::node_type;
423 using insert_return_type = _Node_insert_return<iterator, node_type>;
430 return _Base::extract(__position.
base());
434 extract(
const key_type& __key)
436 const auto __position = find(__key);
437 if (__position != end())
438 return extract(__position);
443 insert(node_type&& __nh)
445 auto __ret = _Base::insert(std::move(__nh));
447 return { __pos, __ret.inserted, std::move(__ret.node) };
454 return iterator(_Base::insert(__hint.
base(), std::move(__nh)),
this);
460 #if __cplusplus >= 201103L 478 _Base::erase(__position.
base());
483 erase(
const key_type& __x)
486 if (__victim == _Base::end())
491 _Base::erase(__victim);
496 #if __cplusplus >= 201103L 504 __victim != __last.
base(); ++__victim)
506 _GLIBCXX_DEBUG_VERIFY(__victim != _Base::end(),
507 _M_message(__gnu_debug::__msg_valid_range)
508 ._M_iterator(__first,
"first")
509 ._M_iterator(__last,
"last"));
522 __victim != __last.
base(); ++__victim)
524 _GLIBCXX_DEBUG_VERIFY(__victim != _Base::end(),
525 _M_message(__gnu_debug::__msg_valid_range)
526 ._M_iterator(__first,
"first")
527 ._M_iterator(__last,
"last"));
530 _Base::erase(__first.
base(), __last.
base());
536 _GLIBCXX_NOEXCEPT_IF( noexcept(declval<_Base&>().swap(__x)) )
543 clear() _GLIBCXX_NOEXCEPT
545 this->_M_invalidate_all();
550 using _Base::key_comp;
551 using _Base::value_comp;
555 find(
const key_type& __x)
556 {
return iterator(_Base::find(__x),
this); }
558 #if __cplusplus > 201103L 559 template<
typename _Kt,
561 typename __has_is_transparent<_Compare, _Kt>::type>
564 {
return { _Base::find(__x),
this }; }
568 find(
const key_type& __x)
const 571 #if __cplusplus > 201103L 572 template<
typename _Kt,
574 typename __has_is_transparent<_Compare, _Kt>::type>
576 find(
const _Kt& __x)
const 577 {
return { _Base::find(__x),
this }; }
583 lower_bound(
const key_type& __x)
584 {
return iterator(_Base::lower_bound(__x),
this); }
586 #if __cplusplus > 201103L 587 template<
typename _Kt,
589 typename __has_is_transparent<_Compare, _Kt>::type>
591 lower_bound(
const _Kt& __x)
592 {
return { _Base::lower_bound(__x),
this }; }
596 lower_bound(
const key_type& __x)
const 599 #if __cplusplus > 201103L 600 template<
typename _Kt,
602 typename __has_is_transparent<_Compare, _Kt>::type>
604 lower_bound(
const _Kt& __x)
const 605 {
return { _Base::lower_bound(__x),
this }; }
609 upper_bound(
const key_type& __x)
610 {
return iterator(_Base::upper_bound(__x),
this); }
612 #if __cplusplus > 201103L 613 template<
typename _Kt,
615 typename __has_is_transparent<_Compare, _Kt>::type>
617 upper_bound(
const _Kt& __x)
618 {
return { _Base::upper_bound(__x),
this }; }
622 upper_bound(
const key_type& __x)
const 625 #if __cplusplus > 201103L 626 template<
typename _Kt,
628 typename __has_is_transparent<_Compare, _Kt>::type>
630 upper_bound(
const _Kt& __x)
const 631 {
return { _Base::upper_bound(__x),
this }; }
635 equal_range(
const key_type& __x)
638 _Base::equal_range(__x);
643 #if __cplusplus > 201103L 644 template<
typename _Kt,
646 typename __has_is_transparent<_Compare, _Kt>::type>
648 equal_range(
const _Kt& __x)
650 auto __res = _Base::equal_range(__x);
651 return { { __res.first,
this }, { __res.second,
this } };
656 equal_range(
const key_type& __x)
const 659 _Base::equal_range(__x);
664 #if __cplusplus > 201103L 665 template<
typename _Kt,
667 typename __has_is_transparent<_Compare, _Kt>::type>
669 equal_range(
const _Kt& __x)
const 671 auto __res = _Base::equal_range(__x);
672 return { { __res.first,
this }, { __res.second,
this } };
677 _M_base() _GLIBCXX_NOEXCEPT {
return *
this; }
680 _M_base()
const _GLIBCXX_NOEXCEPT {
return *
this; }
683 #if __cpp_deduction_guides >= 201606 685 template<
typename _InputIterator,
688 typename = _RequireInputIter<_InputIterator>,
689 typename = _RequireAllocator<_Allocator>>
690 map(_InputIterator, _InputIterator,
691 _Compare = _Compare(), _Allocator = _Allocator())
693 _Compare, _Allocator>;
695 template<
typename _Key,
typename _Tp,
typename _Compare = less<_Key>,
696 typename _Allocator = allocator<pair<const _Key, _Tp>>,
697 typename = _RequireAllocator<_Allocator>>
699 _Compare = _Compare(), _Allocator = _Allocator())
702 template <
typename _InputIterator,
typename _Allocator,
703 typename = _RequireInputIter<_InputIterator>,
704 typename = _RequireAllocator<_Allocator>>
705 map(_InputIterator, _InputIterator, _Allocator)
709 template<
typename _Key,
typename _Tp,
typename _Allocator,
710 typename = _RequireAllocator<_Allocator>>
716 template<
typename _Key,
typename _Tp,
717 typename _Compare,
typename _Allocator>
721 {
return __lhs._M_base() == __rhs._M_base(); }
723 template<
typename _Key,
typename _Tp,
724 typename _Compare,
typename _Allocator>
728 {
return __lhs._M_base() != __rhs._M_base(); }
730 template<
typename _Key,
typename _Tp,
731 typename _Compare,
typename _Allocator>
733 operator<(
const map<_Key, _Tp, _Compare, _Allocator>& __lhs,
734 const map<_Key, _Tp, _Compare, _Allocator>& __rhs)
735 {
return __lhs._M_base() < __rhs._M_base(); }
737 template<
typename _Key,
typename _Tp,
738 typename _Compare,
typename _Allocator>
740 operator<=(
const map<_Key, _Tp, _Compare, _Allocator>& __lhs,
741 const map<_Key, _Tp, _Compare, _Allocator>& __rhs)
742 {
return __lhs._M_base() <= __rhs._M_base(); }
744 template<
typename _Key,
typename _Tp,
745 typename _Compare,
typename _Allocator>
747 operator>=(
const map<_Key, _Tp, _Compare, _Allocator>& __lhs,
748 const map<_Key, _Tp, _Compare, _Allocator>& __rhs)
749 {
return __lhs._M_base() >= __rhs._M_base(); }
751 template<
typename _Key,
typename _Tp,
752 typename _Compare,
typename _Allocator>
754 operator>(
const map<_Key, _Tp, _Compare, _Allocator>& __lhs,
755 const map<_Key, _Tp, _Compare, _Allocator>& __rhs)
756 {
return __lhs._M_base() > __rhs._M_base(); }
758 template<
typename _Key,
typename _Tp,
759 typename _Compare,
typename _Allocator>
761 swap(map<_Key, _Tp, _Compare, _Allocator>& __lhs,
762 map<_Key, _Tp, _Compare, _Allocator>& __rhs)
763 _GLIBCXX_NOEXCEPT_IF(noexcept(__lhs.swap(__rhs)))
764 { __lhs.swap(__rhs); }
Like _Safe_sequence but with a special _M_invalidate_all implementation not invalidating past-the-end...
One of the comparison functors.
Struct holding two objects of arbitrary type.
The standard allocator, as per [20.4].
Define a member typedef type only if a boolean constant is true.
#define __glibcxx_check_erase(_Position)
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.
#define __glibcxx_check_insert(_Position)
ISO C++ entities toplevel namespace is std.
_Iterator & base() noexcept
Return the underlying iterator.
void _M_invalidate_if(_Predicate __pred)
#define __glibcxx_check_erase_range(_First, _Last)
Class std::map with safety/checking/debug instrumentation.
_T1 first
second_type is the second bound type
A standard container made up of (key,value) pairs, which can be retrieved based on a key,...
_T2 second
first is a copy of the first object
Safe class dealing with some allocator dependent operations.