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 92 map(
const map&) =
default;
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)
125 map(
const _Base& __x)
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
176 {
return const_iterator(_Base::begin(),
this); }
179 end() _GLIBCXX_NOEXCEPT
180 {
return iterator(_Base::end(),
this); }
183 end()
const _GLIBCXX_NOEXCEPT
184 {
return const_iterator(_Base::end(),
this); }
187 rbegin() _GLIBCXX_NOEXCEPT
188 {
return reverse_iterator(end()); }
190 const_reverse_iterator
191 rbegin()
const _GLIBCXX_NOEXCEPT
192 {
return const_reverse_iterator(end()); }
195 rend() _GLIBCXX_NOEXCEPT
196 {
return reverse_iterator(begin()); }
198 const_reverse_iterator
199 rend()
const _GLIBCXX_NOEXCEPT
200 {
return const_reverse_iterator(begin()); }
202 #if __cplusplus >= 201103L 204 cbegin()
const noexcept
205 {
return const_iterator(_Base::begin(),
this); }
208 cend()
const noexcept
209 {
return const_iterator(_Base::end(),
this); }
211 const_reverse_iterator
212 crbegin()
const noexcept
213 {
return const_reverse_iterator(end()); }
215 const_reverse_iterator
216 crend()
const noexcept
217 {
return const_reverse_iterator(begin()); }
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>
245 emplace_hint(const_iterator __pos, _Args&&... __args)
248 return iterator(_Base::emplace_hint(__pos.
base(),
249 std::forward<_Args>(__args)...),
255 insert(
const value_type& __x)
262 #if __cplusplus >= 201103L 266 insert(value_type&& __x)
268 auto __res = _Base::insert(std::move(__x));
269 return { iterator(__res.first,
this), __res.second };
272 template<
typename _Pair,
typename =
typename 273 std::enable_if<std::is_constructible<value_type,
274 _Pair&&>::value>::type>
279 = _Base::insert(std::forward<_Pair>(__x));
285 #if __cplusplus >= 201103L 288 { _Base::insert(__list); }
292 #if __cplusplus >= 201103L 293 insert(const_iterator __position,
const value_type& __x)
295 insert(iterator __position,
const value_type& __x)
299 return iterator(_Base::insert(__position.
base(), __x),
this);
302 #if __cplusplus >= 201103L 306 insert(const_iterator __position, value_type&& __x)
309 return { _Base::insert(__position.
base(), std::move(__x)),
this };
312 template<
typename _Pair,
typename =
typename 313 std::enable_if<std::is_constructible<value_type,
314 _Pair&&>::value>::type>
316 insert(const_iterator __position, _Pair&& __x)
319 return iterator(_Base::insert(__position.
base(),
320 std::forward<_Pair>(__x)),
this);
324 template<
typename _InputIterator>
326 insert(_InputIterator __first, _InputIterator __last)
329 __glibcxx_check_valid_range2(__first, __last, __dist);
331 if (__dist.
second >= __gnu_debug::__dp_sign)
332 _Base::insert(__gnu_debug::__unsafe(__first),
333 __gnu_debug::__unsafe(__last));
335 _Base::insert(__first, __last);
339 #if __cplusplus > 201402L 340 template <
typename... _Args>
342 try_emplace(
const key_type& __k, _Args&&... __args)
344 auto __res = _Base::try_emplace(__k,
345 std::forward<_Args>(__args)...);
346 return { iterator(__res.first,
this), __res.second };
349 template <
typename... _Args>
351 try_emplace(key_type&& __k, _Args&&... __args)
353 auto __res = _Base::try_emplace(std::move(__k),
354 std::forward<_Args>(__args)...);
355 return { iterator(__res.first,
this), __res.second };
358 template <
typename... _Args>
360 try_emplace(const_iterator __hint,
const key_type& __k,
364 return iterator(_Base::try_emplace(__hint.
base(), __k,
365 std::forward<_Args>(__args)...),
369 template <
typename... _Args>
371 try_emplace(const_iterator __hint, key_type&& __k, _Args&&... __args)
374 return iterator(_Base::try_emplace(__hint.
base(), std::move(__k),
375 std::forward<_Args>(__args)...),
379 template <
typename _Obj>
381 insert_or_assign(
const key_type& __k, _Obj&& __obj)
383 auto __res = _Base::insert_or_assign(__k,
384 std::forward<_Obj>(__obj));
385 return { iterator(__res.first,
this), __res.second };
388 template <
typename _Obj>
390 insert_or_assign(key_type&& __k, _Obj&& __obj)
392 auto __res = _Base::insert_or_assign(std::move(__k),
393 std::forward<_Obj>(__obj));
394 return { iterator(__res.first,
this), __res.second };
397 template <
typename _Obj>
399 insert_or_assign(const_iterator __hint,
400 const key_type& __k, _Obj&& __obj)
403 return iterator(_Base::insert_or_assign(__hint.
base(), __k,
404 std::forward<_Obj>(__obj)),
408 template <
typename _Obj>
410 insert_or_assign(const_iterator __hint, key_type&& __k, _Obj&& __obj)
413 return iterator(_Base::insert_or_assign(__hint.
base(),
415 std::forward<_Obj>(__obj)),
420 #if __cplusplus > 201402L 421 using node_type =
typename _Base::node_type;
423 struct insert_return_type
431 extract(const_iterator __position)
435 return _Base::extract(__position.
base());
439 extract(
const key_type& __key)
441 const auto __position = find(__key);
442 if (__position !=
end())
443 return extract(__position);
448 insert(node_type&& __nh)
450 auto __ret = _Base::insert(std::move(__nh));
451 iterator __pos = iterator(__ret.position,
this);
452 return { __ret.inserted, __pos, std::move(__ret.node) };
456 insert(const_iterator __hint, node_type&& __nh)
459 return iterator(_Base::insert(__hint.
base(), std::move(__nh)),
this);
465 #if __cplusplus >= 201103L 467 erase(const_iterator __position)
471 return iterator(_Base::erase(__position.
base()),
this);
475 erase(iterator __position)
476 {
return erase(const_iterator(__position)); }
479 erase(iterator __position)
483 _Base::erase(__position.
base());
488 erase(
const key_type& __x)
490 _Base_iterator __victim = _Base::find(__x);
491 if (__victim == _Base::end())
496 _Base::erase(__victim);
501 #if __cplusplus >= 201103L 503 erase(const_iterator __first, const_iterator __last)
508 for (_Base_const_iterator __victim = __first.
base();
509 __victim != __last.
base(); ++__victim)
511 _GLIBCXX_DEBUG_VERIFY(__victim != _Base::end(),
512 _M_message(__gnu_debug::__msg_valid_range)
513 ._M_iterator(__first,
"first")
514 ._M_iterator(__last,
"last"));
517 return iterator(_Base::erase(__first.
base(), __last.
base()),
this);
521 erase(iterator __first, iterator __last)
526 for (_Base_iterator __victim = __first.
base();
527 __victim != __last.
base(); ++__victim)
529 _GLIBCXX_DEBUG_VERIFY(__victim != _Base::end(),
530 _M_message(__gnu_debug::__msg_valid_range)
531 ._M_iterator(__first,
"first")
532 ._M_iterator(__last,
"last"));
535 _Base::erase(__first.
base(), __last.
base());
541 _GLIBCXX_NOEXCEPT_IF( noexcept(declval<_Base&>().swap(__x)) )
548 clear() _GLIBCXX_NOEXCEPT
550 this->_M_invalidate_all();
555 using _Base::key_comp;
556 using _Base::value_comp;
560 find(
const key_type& __x)
561 {
return iterator(_Base::find(__x),
this); }
563 #if __cplusplus > 201103L 564 template<
typename _Kt,
566 typename __has_is_transparent<_Compare, _Kt>::type>
569 {
return { _Base::find(__x),
this }; }
573 find(
const key_type& __x)
const 574 {
return const_iterator(_Base::find(__x),
this); }
576 #if __cplusplus > 201103L 577 template<
typename _Kt,
579 typename __has_is_transparent<_Compare, _Kt>::type>
581 find(
const _Kt& __x)
const 582 {
return { _Base::find(__x),
this }; }
588 lower_bound(
const key_type& __x)
589 {
return iterator(_Base::lower_bound(__x),
this); }
591 #if __cplusplus > 201103L 592 template<
typename _Kt,
594 typename __has_is_transparent<_Compare, _Kt>::type>
596 lower_bound(
const _Kt& __x)
597 {
return { _Base::lower_bound(__x),
this }; }
601 lower_bound(
const key_type& __x)
const 602 {
return const_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)
const 610 {
return { _Base::lower_bound(__x),
this }; }
614 upper_bound(
const key_type& __x)
615 {
return iterator(_Base::upper_bound(__x),
this); }
617 #if __cplusplus > 201103L 618 template<
typename _Kt,
620 typename __has_is_transparent<_Compare, _Kt>::type>
622 upper_bound(
const _Kt& __x)
623 {
return { _Base::upper_bound(__x),
this }; }
627 upper_bound(
const key_type& __x)
const 628 {
return const_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)
const 636 {
return { _Base::upper_bound(__x),
this }; }
640 equal_range(
const key_type& __x)
643 _Base::equal_range(__x);
645 iterator(__res.
second,
this));
648 #if __cplusplus > 201103L 649 template<
typename _Kt,
651 typename __has_is_transparent<_Compare, _Kt>::type>
653 equal_range(
const _Kt& __x)
655 auto __res = _Base::equal_range(__x);
656 return { { __res.first,
this }, { __res.second,
this } };
661 equal_range(
const key_type& __x)
const 664 _Base::equal_range(__x);
666 const_iterator(__res.
second,
this));
669 #if __cplusplus > 201103L 670 template<
typename _Kt,
672 typename __has_is_transparent<_Compare, _Kt>::type>
674 equal_range(
const _Kt& __x)
const 676 auto __res = _Base::equal_range(__x);
677 return { { __res.first,
this }, { __res.second,
this } };
682 _M_base() _GLIBCXX_NOEXCEPT {
return *
this; }
685 _M_base()
const _GLIBCXX_NOEXCEPT {
return *
this; }
688 template<
typename _Key,
typename _Tp,
689 typename _Compare,
typename _Allocator>
693 {
return __lhs._M_base() == __rhs._M_base(); }
695 template<
typename _Key,
typename _Tp,
696 typename _Compare,
typename _Allocator>
700 {
return __lhs._M_base() != __rhs._M_base(); }
702 template<
typename _Key,
typename _Tp,
703 typename _Compare,
typename _Allocator>
705 operator<(const map<_Key, _Tp, _Compare, _Allocator>& __lhs,
707 {
return __lhs._M_base() < __rhs._M_base(); }
709 template<
typename _Key,
typename _Tp,
710 typename _Compare,
typename _Allocator>
712 operator<=(const map<_Key, _Tp, _Compare, _Allocator>& __lhs,
714 {
return __lhs._M_base() <= __rhs._M_base(); }
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>
735 _GLIBCXX_NOEXCEPT_IF(noexcept(__lhs.swap(__rhs)))
736 { __lhs.swap(__rhs); }
Class std::map with safety/checking/debug instrumentation.
Safe class dealing with some allocator dependent operations.
#define __glibcxx_check_insert(_Position)
_T2 second
first is a copy of the first object
constexpr const _Tp * end(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to one past the last element of the initializer_list. ...
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.
Like _Safe_sequence but with a special _M_invalidate_all implementation not invalidating past-the-end...
Struct holding two objects of arbitrary type.
#define __glibcxx_check_erase(_Position)
#define __glibcxx_check_erase_range(_First, _Last)
ISO C++ entities toplevel namespace is std.
_Iterator & base() noexcept
Return the underlying iterator.
_T1 first
second_type is the second bound type