29 #ifndef _GLIBCXX_DEBUG_DEQUE
30 #define _GLIBCXX_DEBUG_DEQUE 1
32 #pragma GCC system_header
35 namespace std _GLIBCXX_VISIBILITY(default) {
namespace __debug {
36 template<
typename _Tp,
typename _Allocator>
class deque;
44 namespace std _GLIBCXX_VISIBILITY(default)
49 template<
typename _Tp,
typename _Allocator = std::allocator<_Tp> >
52 deque<_Tp, _Allocator>, _Allocator,
53 __gnu_debug::_Safe_sequence>,
54 public _GLIBCXX_STD_C::deque<_Tp, _Allocator>
56 typedef _GLIBCXX_STD_C::deque<_Tp, _Allocator> _Base;
60 typedef typename _Base::const_iterator _Base_const_iterator;
61 typedef typename _Base::iterator _Base_iterator;
64 template<
typename _ItT,
typename _SeqT,
typename _CatT>
65 friend class ::__gnu_debug::_Safe_iterator;
72 _Base_ref(
const _Base& __r) : _M_ref(__r) { }
78 typedef typename _Base::reference reference;
79 typedef typename _Base::const_reference const_reference;
86 typedef typename _Base::size_type size_type;
87 typedef typename _Base::difference_type difference_type;
89 typedef _Tp value_type;
90 typedef _Allocator allocator_type;
91 typedef typename _Base::pointer pointer;
92 typedef typename _Base::const_pointer const_pointer;
98 #if __cplusplus < 201103L
102 deque(
const deque& __x)
108 deque(
const deque&) =
default;
109 deque(deque&&) =
default;
111 deque(
const deque& __d,
const _Allocator& __a)
112 : _Base(__d, __a) { }
114 deque(deque&& __d,
const _Allocator& __a)
115 : _Safe(std::
move(__d)), _Base(std::
move(__d), __a) { }
117 deque(initializer_list<value_type> __l,
118 const allocator_type& __a = allocator_type())
119 : _Base(__l, __a) { }
125 deque(
const _Allocator& __a)
128 #if __cplusplus >= 201103L
130 deque(size_type __n,
const _Allocator& __a = _Allocator())
131 : _Base(__n, __a) { }
133 deque(size_type __n,
const _Tp& __value,
134 const _Allocator& __a = _Allocator())
135 : _Base(__n, __value, __a) { }
138 deque(size_type __n,
const _Tp& __value = _Tp(),
139 const _Allocator& __a = _Allocator())
140 : _Base(__n, __value, __a) { }
143 #if __cplusplus >= 201103L
144 template<
class _InputIterator,
145 typename = std::_RequireInputIter<_InputIterator>>
147 template<
class _InputIterator>
149 deque(_InputIterator __first, _InputIterator __last,
150 const _Allocator& __a = _Allocator())
151 : _Base(__gnu_debug::
__base(
152 __glibcxx_check_valid_constructor_range(__first, __last)),
153 __gnu_debug::
__base(__last), __a)
157 : _Base(__x._M_ref) { }
159 #if __cplusplus < 201103L
161 operator=(
const deque& __x)
163 this->_M_safe() = __x;
169 operator=(
const deque&) =
default;
172 operator=(deque&&) =
default;
175 operator=(initializer_list<value_type> __l)
178 this->_M_invalidate_all();
183 #if __cplusplus >= 201103L
184 template<
class _InputIterator,
185 typename = std::_RequireInputIter<_InputIterator>>
187 template<
class _InputIterator>
190 assign(_InputIterator __first, _InputIterator __last)
193 __glibcxx_check_valid_range2(__first, __last, __dist);
194 if (__dist.
second >= __gnu_debug::__dp_sign)
195 _Base::assign(__gnu_debug::__unsafe(__first),
196 __gnu_debug::__unsafe(__last));
198 _Base::assign(__first, __last);
200 this->_M_invalidate_all();
204 assign(size_type __n,
const _Tp& __t)
206 _Base::assign(__n, __t);
207 this->_M_invalidate_all();
210 #if __cplusplus >= 201103L
212 assign(initializer_list<value_type> __l)
215 this->_M_invalidate_all();
219 using _Base::get_allocator;
223 begin() _GLIBCXX_NOEXCEPT
224 {
return iterator(_Base::begin(),
this); }
227 begin() const _GLIBCXX_NOEXCEPT
228 {
return const_iterator(_Base::begin(),
this); }
231 end() _GLIBCXX_NOEXCEPT
232 {
return iterator(_Base::end(),
this); }
235 end() const _GLIBCXX_NOEXCEPT
236 {
return const_iterator(_Base::end(),
this); }
239 rbegin() _GLIBCXX_NOEXCEPT
240 {
return reverse_iterator(end()); }
242 const_reverse_iterator
243 rbegin() const _GLIBCXX_NOEXCEPT
244 {
return const_reverse_iterator(end()); }
247 rend() _GLIBCXX_NOEXCEPT
248 {
return reverse_iterator(begin()); }
250 const_reverse_iterator
251 rend() const _GLIBCXX_NOEXCEPT
252 {
return const_reverse_iterator(begin()); }
254 #if __cplusplus >= 201103L
256 cbegin() const noexcept
257 {
return const_iterator(_Base::begin(),
this); }
260 cend() const noexcept
261 {
return const_iterator(_Base::end(),
this); }
263 const_reverse_iterator
264 crbegin() const noexcept
265 {
return const_reverse_iterator(end()); }
267 const_reverse_iterator
268 crend() const noexcept
269 {
return const_reverse_iterator(begin()); }
274 _M_invalidate_after_nth(difference_type __n)
283 using _Base::max_size;
285 #if __cplusplus >= 201103L
287 resize(size_type __sz)
289 bool __invalidate_all = __sz > this->
size();
290 if (__sz < this->
size())
291 this->_M_invalidate_after_nth(__sz);
295 if (__invalidate_all)
296 this->_M_invalidate_all();
300 resize(size_type __sz,
const _Tp& __c)
302 bool __invalidate_all = __sz > this->
size();
303 if (__sz < this->
size())
304 this->_M_invalidate_after_nth(__sz);
306 _Base::resize(__sz, __c);
308 if (__invalidate_all)
309 this->_M_invalidate_all();
313 resize(size_type __sz, _Tp __c = _Tp())
315 bool __invalidate_all = __sz > this->
size();
316 if (__sz < this->
size())
317 this->_M_invalidate_after_nth(__sz);
319 _Base::resize(__sz, __c);
321 if (__invalidate_all)
322 this->_M_invalidate_all();
326 #if __cplusplus >= 201103L
328 shrink_to_fit() noexcept
330 if (_Base::_M_shrink_to_fit())
331 this->_M_invalidate_all();
339 operator[](size_type __n) _GLIBCXX_NOEXCEPT
341 __glibcxx_check_subscript(__n);
342 return _M_base()[__n];
346 operator[](size_type __n)
const _GLIBCXX_NOEXCEPT
348 __glibcxx_check_subscript(__n);
349 return _M_base()[__n];
355 front() _GLIBCXX_NOEXCEPT
357 __glibcxx_check_nonempty();
358 return _Base::front();
362 front() const _GLIBCXX_NOEXCEPT
364 __glibcxx_check_nonempty();
365 return _Base::front();
369 back() _GLIBCXX_NOEXCEPT
371 __glibcxx_check_nonempty();
372 return _Base::back();
376 back() const _GLIBCXX_NOEXCEPT
378 __glibcxx_check_nonempty();
379 return _Base::back();
384 push_front(
const _Tp& __x)
386 _Base::push_front(__x);
387 this->_M_invalidate_all();
391 push_back(
const _Tp& __x)
393 _Base::push_back(__x);
394 this->_M_invalidate_all();
397 #if __cplusplus >= 201103L
399 push_front(_Tp&& __x)
406 template<
typename... _Args>
407 #if __cplusplus > 201402L
412 emplace_front(_Args&&... __args)
414 _Base::emplace_front(std::forward<_Args>(__args)...);
415 this->_M_invalidate_all();
416 #if __cplusplus > 201402L
421 template<
typename... _Args>
422 #if __cplusplus > 201402L
427 emplace_back(_Args&&... __args)
429 _Base::emplace_back(std::forward<_Args>(__args)...);
430 this->_M_invalidate_all();
431 #if __cplusplus > 201402L
436 template<
typename... _Args>
438 emplace(const_iterator __position, _Args&&... __args)
441 _Base_iterator __res = _Base::emplace(__position.base(),
442 std::forward<_Args>(__args)...);
443 this->_M_invalidate_all();
444 return iterator(__res,
this);
449 #if __cplusplus >= 201103L
450 insert(const_iterator __position,
const _Tp& __x)
452 insert(iterator __position,
const _Tp& __x)
456 _Base_iterator __res = _Base::insert(__position.base(), __x);
457 this->_M_invalidate_all();
458 return iterator(__res,
this);
461 #if __cplusplus >= 201103L
463 insert(const_iterator __position, _Tp&& __x)
464 {
return emplace(__position,
std::move(__x)); }
467 insert(const_iterator __position, initializer_list<value_type> __l)
470 _Base_iterator __res = _Base::insert(__position.base(), __l);
471 this->_M_invalidate_all();
472 return iterator(__res,
this);
476 #if __cplusplus >= 201103L
478 insert(const_iterator __position, size_type __n,
const _Tp& __x)
481 _Base_iterator __res = _Base::insert(__position.base(), __n, __x);
482 this->_M_invalidate_all();
483 return iterator(__res,
this);
487 insert(iterator __position, size_type __n,
const _Tp& __x)
490 _Base::insert(__position.base(), __n, __x);
491 this->_M_invalidate_all();
495 #if __cplusplus >= 201103L
496 template<
class _InputIterator,
497 typename = std::_RequireInputIter<_InputIterator>>
499 insert(const_iterator __position,
500 _InputIterator __first, _InputIterator __last)
504 _Base_iterator __res;
505 if (__dist.
second >= __gnu_debug::__dp_sign)
506 __res = _Base::insert(__position.base(),
507 __gnu_debug::__unsafe(__first),
508 __gnu_debug::__unsafe(__last));
510 __res = _Base::insert(__position.base(), __first, __last);
512 this->_M_invalidate_all();
513 return iterator(__res,
this);
516 template<
class _InputIterator>
518 insert(iterator __position,
519 _InputIterator __first, _InputIterator __last)
524 if (__dist.
second >= __gnu_debug::__dp_sign)
525 _Base::insert(__position.base(),
526 __gnu_debug::__unsafe(__first),
527 __gnu_debug::__unsafe(__last));
529 _Base::insert(__position.base(), __first, __last);
531 this->_M_invalidate_all();
536 pop_front() _GLIBCXX_NOEXCEPT
538 __glibcxx_check_nonempty();
544 pop_back() _GLIBCXX_NOEXCEPT
546 __glibcxx_check_nonempty();
552 #if __cplusplus >= 201103L
553 erase(const_iterator __position)
555 erase(iterator __position)
559 #if __cplusplus >= 201103L
560 _Base_const_iterator __victim = __position.
base();
562 _Base_iterator __victim = __position.
base();
564 if (__victim == _Base::begin() || __victim == _Base::end() - 1)
567 return iterator(_Base::erase(__victim),
this);
571 _Base_iterator __res = _Base::erase(__victim);
572 this->_M_invalidate_all();
573 return iterator(__res,
this);
578 #if __cplusplus >= 201103L
579 erase(const_iterator __first, const_iterator __last)
581 erase(iterator __first, iterator __last)
588 if (__first.base() == __last.base())
589 #
if __cplusplus >= 201103L
590 return iterator(__first.base()._M_const_cast(),
this);
594 else if (__first.base() == _Base::begin()
595 || __last.base() == _Base::end())
598 for (_Base_const_iterator __position = __first.base();
599 __position != __last.base(); ++__position)
605 return iterator(_Base::erase(__first.base(), __last.base()),
611 __throw_exception_again;
616 _Base_iterator __res = _Base::erase(__first.base(),
618 this->_M_invalidate_all();
619 return iterator(__res,
this);
625 _GLIBCXX_NOEXCEPT_IF( noexcept(declval<_Base&>().swap(__x)) )
632 clear() _GLIBCXX_NOEXCEPT
635 this->_M_invalidate_all();
639 _M_base() _GLIBCXX_NOEXCEPT {
return *
this; }
642 _M_base() const _GLIBCXX_NOEXCEPT {
return *
this; }
645 #if __cpp_deduction_guides >= 201606
646 template<
typename _InputIterator,
typename _ValT
647 =
typename iterator_traits<_InputIterator>::value_type,
648 typename _Allocator = allocator<_ValT>,
649 typename = _RequireInputIter<_InputIterator>,
650 typename = _RequireAllocator<_Allocator>>
651 deque(_InputIterator, _InputIterator, _Allocator = _Allocator())
652 -> deque<_ValT, _Allocator>;
655 template<
typename _Tp,
typename _Alloc>
657 operator==(
const deque<_Tp, _Alloc>& __lhs,
658 const deque<_Tp, _Alloc>& __rhs)
659 {
return __lhs._M_base() == __rhs._M_base(); }
661 #if __cpp_lib_three_way_comparison
662 template<
typename _Tp,
typename _Alloc>
663 constexpr __detail::__synth3way_t<_Tp>
664 operator<=>(
const deque<_Tp, _Alloc>& __x,
const deque<_Tp, _Alloc>& __y)
665 {
return __x._M_base() <=> __y._M_base(); }
667 template<
typename _Tp,
typename _Alloc>
669 operator!=(
const deque<_Tp, _Alloc>& __lhs,
670 const deque<_Tp, _Alloc>& __rhs)
671 {
return __lhs._M_base() != __rhs._M_base(); }
673 template<
typename _Tp,
typename _Alloc>
675 operator<(const deque<_Tp, _Alloc>& __lhs,
676 const deque<_Tp, _Alloc>& __rhs)
677 {
return __lhs._M_base() < __rhs._M_base(); }
679 template<
typename _Tp,
typename _Alloc>
681 operator<=(const deque<_Tp, _Alloc>& __lhs,
682 const deque<_Tp, _Alloc>& __rhs)
683 {
return __lhs._M_base() <= __rhs._M_base(); }
685 template<
typename _Tp,
typename _Alloc>
687 operator>=(
const deque<_Tp, _Alloc>& __lhs,
688 const deque<_Tp, _Alloc>& __rhs)
689 {
return __lhs._M_base() >= __rhs._M_base(); }
691 template<
typename _Tp,
typename _Alloc>
693 operator>(
const deque<_Tp, _Alloc>& __lhs,
694 const deque<_Tp, _Alloc>& __rhs)
695 {
return __lhs._M_base() > __rhs._M_base(); }
696 #endif // three-way comparison
698 template<
typename _Tp,
typename _Alloc>
700 swap(deque<_Tp, _Alloc>& __lhs, deque<_Tp, _Alloc>& __rhs)
701 _GLIBCXX_NOEXCEPT_IF(noexcept(__lhs.swap(__rhs)))
702 { __lhs.swap(__rhs); }
void _M_invalidate_if(_Predicate __pred)
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
Struct holding two objects of arbitrary type.
Base class for constructing a safe sequence type that tracks iterators that reference it...
void _M_detach_singular()
_Iterator & base() noexcept
Return the underlying iterator.
#define __glibcxx_check_erase(_Position)
void _M_revalidate_singular()
Class std::deque with safety/checking/debug instrumentation.
constexpr _Iterator __base(_Iterator __it)
Safe class dealing with some allocator dependent operations.
constexpr auto empty(const _Container &__cont) noexcept(noexcept(__cont.empty())) -> decltype(__cont.empty())
Return whether a container is empty.
_T2 second
The second member.
#define __glibcxx_check_erase_range(_First, _Last)
#define __glibcxx_check_insert(_Position)
#define __glibcxx_check_insert_range(_Position, _First, _Last, _Dist)
A standard container using fixed-size memory allocation and constant-time manipulation of elements at...
constexpr auto size(const _Container &__cont) noexcept(noexcept(__cont.size())) -> decltype(__cont.size())
Return the size of a container.