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 :
_Safe(std::move(__m._M_safe()), __a),
109 _Base(std::move(__m._M_base()), __a) { }
112 :
_Base(__l, __a) { }
114 template<
typename _InputIterator>
115 map(_InputIterator __first, _InputIterator __last,
116 const allocator_type& __a)
117 :
_Base(__gnu_debug::__base(__gnu_debug::__check_valid_range(__first,
119 __gnu_debug::__base(__last), __a)
128 explicit map(
const _Compare& __comp,
129 const _Allocator& __a = _Allocator())
130 :
_Base(__comp, __a) { }
132 template<
typename _InputIterator>
133 map(_InputIterator __first, _InputIterator __last,
134 const _Compare& __comp = _Compare(),
135 const _Allocator& __a = _Allocator())
136 :
_Base(__gnu_debug::__base(__gnu_debug::__check_valid_range(__first,
138 __gnu_debug::__base(__last),
141 #if __cplusplus < 201103L
143 operator=(
const map& __x)
145 this->_M_safe() = __x;
151 operator=(
const map&) =
default;
154 operator=(
map&&) =
default;
160 this->_M_invalidate_all();
167 using _Base::get_allocator;
171 begin() _GLIBCXX_NOEXCEPT
172 {
return iterator(_Base::begin(),
this); }
175 begin()
const _GLIBCXX_NOEXCEPT
179 end() _GLIBCXX_NOEXCEPT
180 {
return iterator(_Base::end(),
this); }
183 end()
const _GLIBCXX_NOEXCEPT
187 rbegin() _GLIBCXX_NOEXCEPT
191 rbegin()
const _GLIBCXX_NOEXCEPT
195 rend() _GLIBCXX_NOEXCEPT
199 rend()
const _GLIBCXX_NOEXCEPT
202 #if __cplusplus >= 201103L
204 cbegin()
const noexcept
208 cend()
const noexcept
212 crbegin()
const noexcept
216 crend()
const noexcept
223 using _Base::max_size;
226 using _Base::operator[];
233 #if __cplusplus >= 201103L
234 template<
typename... _Args>
236 emplace(_Args&&... __args)
238 auto __res = _Base::emplace(std::forward<_Args>(__args)...);
243 template<
typename... _Args>
249 std::forward<_Args>(__args)...),
262 #if __cplusplus >= 201103L
263 template<
typename _Pair,
typename =
typename
264 std::enable_if<std::is_constructible<
value_type,
265 _Pair&&>::value>::type>
270 = _Base::insert(std::forward<_Pair>(__x));
276 #if __cplusplus >= 201103L
279 { _Base::insert(__list); }
283 #if __cplusplus >= 201103L
290 return iterator(_Base::insert(__position.
base(), __x),
this);
293 #if __cplusplus >= 201103L
294 template<
typename _Pair,
typename =
typename
295 std::enable_if<std::is_constructible<
value_type,
296 _Pair&&>::value>::type>
302 std::forward<_Pair>(__x)),
this);
306 template<
typename _InputIterator>
308 insert(_InputIterator __first, _InputIterator __last)
311 __glibcxx_check_valid_range2(__first, __last, __dist);
313 if (__dist.
second >= __gnu_debug::__dp_sign)
314 _Base::insert(__gnu_debug::__unsafe(__first),
315 __gnu_debug::__unsafe(__last));
317 _Base::insert(__first, __last);
321 #if __cplusplus > 201402L
322 template <
typename... _Args>
324 try_emplace(
const key_type& __k, _Args&&... __args)
326 auto __res = _Base::try_emplace(__k,
327 std::forward<_Args>(__args)...);
328 return {
iterator(__res.first,
this), __res.second };
331 template <
typename... _Args>
333 try_emplace(key_type&& __k, _Args&&... __args)
335 auto __res = _Base::try_emplace(std::move(__k),
336 std::forward<_Args>(__args)...);
337 return {
iterator(__res.first,
this), __res.second };
340 template <
typename... _Args>
347 std::forward<_Args>(__args)...),
351 template <
typename... _Args>
353 try_emplace(
const_iterator __hint, key_type&& __k, _Args&&... __args)
356 return iterator(_Base::try_emplace(__hint.
base(), std::move(__k),
357 std::forward<_Args>(__args)...),
361 template <
typename _Obj>
363 insert_or_assign(
const key_type& __k, _Obj&& __obj)
365 auto __res = _Base::insert_or_assign(__k,
366 std::forward<_Obj>(__obj));
367 return {
iterator(__res.first,
this), __res.second };
370 template <
typename _Obj>
372 insert_or_assign(key_type&& __k, _Obj&& __obj)
374 auto __res = _Base::insert_or_assign(std::move(__k),
375 std::forward<_Obj>(__obj));
376 return {
iterator(__res.first,
this), __res.second };
379 template <
typename _Obj>
382 const key_type& __k, _Obj&& __obj)
385 return iterator(_Base::insert_or_assign(__hint.
base(), __k,
386 std::forward<_Obj>(__obj)),
390 template <
typename _Obj>
392 insert_or_assign(
const_iterator __hint, key_type&& __k, _Obj&& __obj)
397 std::forward<_Obj>(__obj)),
403 #if __cplusplus >= 201103L
421 _Base::erase(__position.
base());
426 erase(
const key_type& __x)
429 if (__victim == _Base::end())
434 _Base::erase(__victim);
439 #if __cplusplus >= 201103L
447 __victim != __last.
base(); ++__victim)
449 _GLIBCXX_DEBUG_VERIFY(__victim != _Base::end(),
450 _M_message(__gnu_debug::__msg_valid_range)
451 ._M_iterator(__first,
"first")
452 ._M_iterator(__last,
"last"));
465 __victim != __last.
base(); ++__victim)
467 _GLIBCXX_DEBUG_VERIFY(__victim != _Base::end(),
468 _M_message(__gnu_debug::__msg_valid_range)
469 ._M_iterator(__first,
"first")
470 ._M_iterator(__last,
"last"));
473 _Base::erase(__first.
base(), __last.
base());
479 _GLIBCXX_NOEXCEPT_IF( noexcept(declval<_Base&>().
swap(__x)) )
486 clear() _GLIBCXX_NOEXCEPT
488 this->_M_invalidate_all();
493 using _Base::key_comp;
494 using _Base::value_comp;
498 find(
const key_type& __x)
499 {
return iterator(_Base::find(__x),
this); }
501 #if __cplusplus > 201103L
502 template<
typename _Kt,
504 typename __has_is_transparent<_Compare, _Kt>::type>
507 {
return { _Base::find(__x),
this }; }
511 find(
const key_type& __x)
const
514 #if __cplusplus > 201103L
515 template<
typename _Kt,
517 typename __has_is_transparent<_Compare, _Kt>::type>
519 find(
const _Kt& __x)
const
520 {
return { _Base::find(__x),
this }; }
526 lower_bound(
const key_type& __x)
527 {
return iterator(_Base::lower_bound(__x),
this); }
529 #if __cplusplus > 201103L
530 template<
typename _Kt,
532 typename __has_is_transparent<_Compare, _Kt>::type>
534 lower_bound(
const _Kt& __x)
535 {
return { _Base::lower_bound(__x),
this }; }
539 lower_bound(
const key_type& __x)
const
542 #if __cplusplus > 201103L
543 template<
typename _Kt,
545 typename __has_is_transparent<_Compare, _Kt>::type>
547 lower_bound(
const _Kt& __x)
const
548 {
return { _Base::lower_bound(__x),
this }; }
552 upper_bound(
const key_type& __x)
553 {
return iterator(_Base::upper_bound(__x),
this); }
555 #if __cplusplus > 201103L
556 template<
typename _Kt,
558 typename __has_is_transparent<_Compare, _Kt>::type>
560 upper_bound(
const _Kt& __x)
561 {
return { _Base::upper_bound(__x),
this }; }
565 upper_bound(
const key_type& __x)
const
568 #if __cplusplus > 201103L
569 template<
typename _Kt,
571 typename __has_is_transparent<_Compare, _Kt>::type>
573 upper_bound(
const _Kt& __x)
const
574 {
return { _Base::upper_bound(__x),
this }; }
578 equal_range(
const key_type& __x)
581 _Base::equal_range(__x);
586 #if __cplusplus > 201103L
587 template<
typename _Kt,
589 typename __has_is_transparent<_Compare, _Kt>::type>
591 equal_range(
const _Kt& __x)
593 auto __res = _Base::equal_range(__x);
594 return { { __res.first,
this }, { __res.second,
this } };
599 equal_range(
const key_type& __x)
const
602 _Base::equal_range(__x);
607 #if __cplusplus > 201103L
608 template<
typename _Kt,
610 typename __has_is_transparent<_Compare, _Kt>::type>
612 equal_range(
const _Kt& __x)
const
614 auto __res = _Base::equal_range(__x);
615 return { { __res.first,
this }, { __res.second,
this } };
620 _M_base() _GLIBCXX_NOEXCEPT {
return *
this; }
623 _M_base()
const _GLIBCXX_NOEXCEPT {
return *
this; }
626 template<
typename _Key,
typename _Tp,
627 typename _Compare,
typename _Allocator>
631 {
return __lhs._M_base() == __rhs._M_base(); }
633 template<
typename _Key,
typename _Tp,
634 typename _Compare,
typename _Allocator>
638 {
return __lhs._M_base() != __rhs._M_base(); }
640 template<
typename _Key,
typename _Tp,
641 typename _Compare,
typename _Allocator>
643 operator<(const map<_Key, _Tp, _Compare, _Allocator>& __lhs,
644 const map<_Key, _Tp, _Compare, _Allocator>& __rhs)
645 {
return __lhs._M_base() < __rhs._M_base(); }
647 template<
typename _Key,
typename _Tp,
648 typename _Compare,
typename _Allocator>
650 operator<=(const map<_Key, _Tp, _Compare, _Allocator>& __lhs,
651 const map<_Key, _Tp, _Compare, _Allocator>& __rhs)
652 {
return __lhs._M_base() <= __rhs._M_base(); }
654 template<
typename _Key,
typename _Tp,
655 typename _Compare,
typename _Allocator>
657 operator>=(
const map<_Key, _Tp, _Compare, _Allocator>& __lhs,
658 const map<_Key, _Tp, _Compare, _Allocator>& __rhs)
659 {
return __lhs._M_base() >= __rhs._M_base(); }
661 template<
typename _Key,
typename _Tp,
662 typename _Compare,
typename _Allocator>
664 operator>(
const map<_Key, _Tp, _Compare, _Allocator>& __lhs,
665 const map<_Key, _Tp, _Compare, _Allocator>& __rhs)
666 {
return __lhs._M_base() > __rhs._M_base(); }
668 template<
typename _Key,
typename _Tp,
669 typename _Compare,
typename _Allocator>
671 swap(map<_Key, _Tp, _Compare, _Allocator>& __lhs,
672 map<_Key, _Tp, _Compare, _Allocator>& __rhs)
673 _GLIBCXX_NOEXCEPT_IF(noexcept(__lhs.swap(__rhs)))
674 { __lhs.swap(__rhs); }
Like _Safe_sequence but with a special _M_invalidate_all implementation not invalidating past-the-end...
#define __glibcxx_check_erase(_Position)
#define __glibcxx_check_insert(_Position)
_Iterator & base() noexcept
Return the underlying iterator.
Safe class dealing with some allocator dependent operations.
Class std::map with safety/checking/debug instrumentation.
void _M_invalidate_if(_Predicate __pred)
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_erase_range(_First, _Last)
void swap(basic_filebuf< _CharT, _Traits > &__x, basic_filebuf< _CharT, _Traits > &__y)
Swap specialization for filebufs.
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
Struct holding two objects of arbitrary type.
_T1 first
second_type is the second bound type