29 #ifndef _GLIBCXX_DEBUG_MULTIMAP_H 30 #define _GLIBCXX_DEBUG_MULTIMAP_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 multimap<_Key, _Tp, _Compare, _Allocator>, _Allocator,
47 __gnu_debug::_Safe_node_sequence>,
48 public _GLIBCXX_STD_C::multimap<_Key, _Tp, _Compare, _Allocator>
50 typedef _GLIBCXX_STD_C::multimap<
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 84 multimap() : _Base() { }
86 multimap(
const multimap& __x)
92 multimap(
const multimap&) =
default;
93 multimap(multimap&&) =
default;
96 const _Compare& __c = _Compare(),
97 const allocator_type& __a = allocator_type())
98 : _Base(__l, __c, __a) { }
101 multimap(
const allocator_type& __a)
104 multimap(
const multimap& __m,
const allocator_type& __a)
105 : _Base(__m, __a) { }
107 multimap(multimap&& __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 multimap(_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) { }
122 ~multimap() =
default;
125 explicit multimap(
const _Compare& __comp,
126 const _Allocator& __a = _Allocator())
127 : _Base(__comp, __a) { }
129 template<
typename _InputIterator>
130 multimap(_InputIterator __first, _InputIterator __last,
131 const _Compare& __comp = _Compare(),
132 const _Allocator& __a = _Allocator())
133 : _Base(__gnu_debug::__base(__gnu_debug::__check_valid_range(__first,
135 __gnu_debug::__base(__last),
138 multimap(
const _Base& __x)
141 #if __cplusplus < 201103L 143 operator=(
const multimap& __x)
145 this->_M_safe() = __x;
151 operator=(
const multimap&) =
default;
154 operator=(multimap&&) =
default;
160 this->_M_invalidate_all();
165 using _Base::get_allocator;
169 begin() _GLIBCXX_NOEXCEPT
170 {
return iterator(_Base::begin(),
this); }
173 begin()
const _GLIBCXX_NOEXCEPT
174 {
return const_iterator(_Base::begin(),
this); }
177 end() _GLIBCXX_NOEXCEPT
178 {
return iterator(_Base::end(),
this); }
181 end()
const _GLIBCXX_NOEXCEPT
182 {
return const_iterator(_Base::end(),
this); }
185 rbegin() _GLIBCXX_NOEXCEPT
186 {
return reverse_iterator(end()); }
188 const_reverse_iterator
189 rbegin()
const _GLIBCXX_NOEXCEPT
190 {
return const_reverse_iterator(end()); }
193 rend() _GLIBCXX_NOEXCEPT
194 {
return reverse_iterator(begin()); }
196 const_reverse_iterator
197 rend()
const _GLIBCXX_NOEXCEPT
198 {
return const_reverse_iterator(begin()); }
200 #if __cplusplus >= 201103L 202 cbegin()
const noexcept
203 {
return const_iterator(_Base::begin(),
this); }
206 cend()
const noexcept
207 {
return const_iterator(_Base::end(),
this); }
209 const_reverse_iterator
210 crbegin()
const noexcept
211 {
return const_reverse_iterator(end()); }
213 const_reverse_iterator
214 crend()
const noexcept
215 {
return const_reverse_iterator(begin()); }
221 using _Base::max_size;
224 #if __cplusplus >= 201103L 225 template<
typename... _Args>
227 emplace(_Args&&... __args)
229 return iterator(_Base::emplace(std::forward<_Args>(__args)...),
this);
232 template<
typename... _Args>
234 emplace_hint(const_iterator __pos, _Args&&... __args)
237 return iterator(_Base::emplace_hint(__pos.
base(),
238 std::forward<_Args>(__args)...),
244 insert(
const value_type& __x)
245 {
return iterator(_Base::insert(__x),
this); }
247 #if __cplusplus >= 201103L 251 insert(value_type&& __x)
252 {
return { _Base::insert(std::move(__x)),
this }; }
254 template<
typename _Pair,
typename =
typename 256 _Pair&&>::value>::type>
259 {
return iterator(_Base::insert(std::forward<_Pair>(__x)),
this); }
262 #if __cplusplus >= 201103L 265 { _Base::insert(__list); }
269 #if __cplusplus >= 201103L 270 insert(const_iterator __position,
const value_type& __x)
272 insert(iterator __position,
const value_type& __x)
276 return iterator(_Base::insert(__position.
base(), __x),
this);
279 #if __cplusplus >= 201103L 283 insert(const_iterator __position, value_type&& __x)
286 return { _Base::insert(__position.
base(), std::move(__x)),
this };
289 template<
typename _Pair,
typename =
typename 291 _Pair&&>::value>::type>
293 insert(const_iterator __position, _Pair&& __x)
296 return iterator(_Base::insert(__position.
base(),
297 std::forward<_Pair>(__x)),
this);
301 template<
typename _InputIterator>
303 insert(_InputIterator __first, _InputIterator __last)
306 __glibcxx_check_valid_range2(__first, __last, __dist);
308 if (__dist.
second >= __gnu_debug::__dp_sign)
309 _Base::insert(__gnu_debug::__unsafe(__first),
310 __gnu_debug::__unsafe(__last));
312 _Base::insert(__first, __last);
315 #if __cplusplus > 201402L 316 using node_type =
typename _Base::node_type;
319 extract(const_iterator __position)
323 return _Base::extract(__position.
base());
327 extract(
const key_type& __key)
329 const auto __position = find(__key);
330 if (__position != end())
331 return extract(__position);
336 insert(node_type&& __nh)
337 {
return iterator(_Base::insert(std::move(__nh)),
this); }
340 insert(const_iterator __hint, node_type&& __nh)
343 return iterator(_Base::insert(__hint.
base(), std::move(__nh)),
this);
349 #if __cplusplus >= 201103L 351 erase(const_iterator __position)
355 return iterator(_Base::erase(__position.
base()),
this);
359 erase(iterator __position)
360 {
return erase(const_iterator(__position)); }
363 erase(iterator __position)
367 _Base::erase(__position.
base());
372 erase(
const key_type& __x)
375 _Base::equal_range(__x);
376 size_type __count = 0;
377 _Base_iterator __victim = __victims.
first;
378 while (__victim != __victims.
second)
381 _Base::erase(__victim++);
387 #if __cplusplus >= 201103L 389 erase(const_iterator __first, const_iterator __last)
394 for (_Base_const_iterator __victim = __first.
base();
395 __victim != __last.
base(); ++__victim)
397 _GLIBCXX_DEBUG_VERIFY(__victim != _Base::end(),
398 _M_message(__gnu_debug::__msg_valid_range)
399 ._M_iterator(__first,
"first")
400 ._M_iterator(__last,
"last"));
403 return iterator(_Base::erase(__first.
base(), __last.
base()),
this);
407 erase(iterator __first, iterator __last)
412 for (_Base_iterator __victim = __first.
base();
413 __victim != __last.
base(); ++__victim)
415 _GLIBCXX_DEBUG_VERIFY(__victim != _Base::end(),
416 _M_message(__gnu_debug::__msg_valid_range)
417 ._M_iterator(__first,
"first")
418 ._M_iterator(__last,
"last"));
421 _Base::erase(__first.
base(), __last.
base());
427 _GLIBCXX_NOEXCEPT_IF( noexcept(declval<_Base&>().swap(__x)) )
434 clear() _GLIBCXX_NOEXCEPT
436 this->_M_invalidate_all();
441 using _Base::key_comp;
442 using _Base::value_comp;
446 find(
const key_type& __x)
447 {
return iterator(_Base::find(__x),
this); }
449 #if __cplusplus > 201103L 450 template<
typename _Kt,
452 typename __has_is_transparent<_Compare, _Kt>::type>
455 {
return { _Base::find(__x),
this }; }
459 find(
const key_type& __x)
const 460 {
return const_iterator(_Base::find(__x),
this); }
462 #if __cplusplus > 201103L 463 template<
typename _Kt,
465 typename __has_is_transparent<_Compare, _Kt>::type>
467 find(
const _Kt& __x)
const 468 {
return { _Base::find(__x),
this }; }
474 lower_bound(
const key_type& __x)
475 {
return iterator(_Base::lower_bound(__x),
this); }
477 #if __cplusplus > 201103L 478 template<
typename _Kt,
480 typename __has_is_transparent<_Compare, _Kt>::type>
482 lower_bound(
const _Kt& __x)
483 {
return { _Base::lower_bound(__x),
this }; }
487 lower_bound(
const key_type& __x)
const 488 {
return const_iterator(_Base::lower_bound(__x),
this); }
490 #if __cplusplus > 201103L 491 template<
typename _Kt,
493 typename __has_is_transparent<_Compare, _Kt>::type>
495 lower_bound(
const _Kt& __x)
const 496 {
return { _Base::lower_bound(__x),
this }; }
500 upper_bound(
const key_type& __x)
501 {
return iterator(_Base::upper_bound(__x),
this); }
503 #if __cplusplus > 201103L 504 template<
typename _Kt,
506 typename __has_is_transparent<_Compare, _Kt>::type>
508 upper_bound(
const _Kt& __x)
509 {
return { _Base::upper_bound(__x),
this }; }
513 upper_bound(
const key_type& __x)
const 514 {
return const_iterator(_Base::upper_bound(__x),
this); }
516 #if __cplusplus > 201103L 517 template<
typename _Kt,
519 typename __has_is_transparent<_Compare, _Kt>::type>
521 upper_bound(
const _Kt& __x)
const 522 {
return { _Base::upper_bound(__x),
this }; }
526 equal_range(
const key_type& __x)
529 _Base::equal_range(__x);
531 iterator(__res.
second,
this));
534 #if __cplusplus > 201103L 535 template<
typename _Kt,
537 typename __has_is_transparent<_Compare, _Kt>::type>
539 equal_range(
const _Kt& __x)
541 auto __res = _Base::equal_range(__x);
542 return { { __res.first,
this }, { __res.second,
this } };
547 equal_range(
const key_type& __x)
const 550 _Base::equal_range(__x);
552 const_iterator(__res.
second,
this));
555 #if __cplusplus > 201103L 556 template<
typename _Kt,
558 typename __has_is_transparent<_Compare, _Kt>::type>
560 equal_range(
const _Kt& __x)
const 562 auto __res = _Base::equal_range(__x);
563 return { { __res.first,
this }, { __res.second,
this } };
568 _M_base() _GLIBCXX_NOEXCEPT {
return *
this; }
571 _M_base()
const _GLIBCXX_NOEXCEPT {
return *
this; }
574 #if __cpp_deduction_guides >= 201606 576 template<
typename _InputIterator,
579 typename = _RequireInputIter<_InputIterator>,
580 typename = _RequireAllocator<_Allocator>>
581 multimap(_InputIterator, _InputIterator,
582 _Compare = _Compare(), _Allocator = _Allocator())
584 _Compare, _Allocator>;
586 template<
typename _Key,
typename _Tp,
typename _Compare = less<_Key>,
587 typename _Allocator = allocator<pair<const _Key, _Tp>>,
588 typename = _RequireAllocator<_Allocator>>
590 _Compare = _Compare(), _Allocator = _Allocator())
593 template<
typename _InputIterator,
typename _Allocator,
594 typename = _RequireInputIter<_InputIterator>,
595 typename = _RequireAllocator<_Allocator>>
596 multimap(_InputIterator, _InputIterator, _Allocator)
600 template<
typename _Key,
typename _Tp,
typename _Allocator,
601 typename = _RequireAllocator<_Allocator>>
607 template<
typename _Key,
typename _Tp,
608 typename _Compare,
typename _Allocator>
612 {
return __lhs._M_base() == __rhs._M_base(); }
614 template<
typename _Key,
typename _Tp,
615 typename _Compare,
typename _Allocator>
619 {
return __lhs._M_base() != __rhs._M_base(); }
621 template<
typename _Key,
typename _Tp,
622 typename _Compare,
typename _Allocator>
624 operator<(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
626 {
return __lhs._M_base() < __rhs._M_base(); }
628 template<
typename _Key,
typename _Tp,
629 typename _Compare,
typename _Allocator>
631 operator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
633 {
return __lhs._M_base() <= __rhs._M_base(); }
635 template<
typename _Key,
typename _Tp,
636 typename _Compare,
typename _Allocator>
640 {
return __lhs._M_base() >= __rhs._M_base(); }
642 template<
typename _Key,
typename _Tp,
643 typename _Compare,
typename _Allocator>
647 {
return __lhs._M_base() > __rhs._M_base(); }
649 template<
typename _Key,
typename _Tp,
650 typename _Compare,
typename _Allocator>
654 _GLIBCXX_NOEXCEPT_IF(noexcept(__lhs.swap(__rhs)))
655 { __lhs.swap(__rhs); }
The standard allocator, as per [20.4].
#define __glibcxx_check_erase_range(_First, _Last)
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 a member typedef type only if a boolean constant is true.
Like _Safe_sequence but with a special _M_invalidate_all implementation not invalidating past-the-end...
ISO C++ entities toplevel namespace is std.
Class std::multimap with safety/checking/debug instrumentation.
#define __glibcxx_check_erase(_Position)
_Iterator & base() noexcept
Return the underlying iterator.
_T2 second
first is a copy of the first object
void _M_invalidate_if(_Predicate __pred)
#define __glibcxx_check_insert(_Position)
One of the comparison functors.
_T1 first
second_type is the second bound type
Safe class dealing with some allocator dependent operations.
Struct holding two objects of arbitrary type.