libstdc++
debug/deque
Go to the documentation of this file.
1// Debugging deque implementation -*- C++ -*-
2
3// Copyright (C) 2003-2026 Free Software Foundation, Inc.
4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 3, or (at your option)
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// Under Section 7 of GPL version 3, you are granted additional
17// permissions described in the GCC Runtime Library Exception, version
18// 3.1, as published by the Free Software Foundation.
19
20// You should have received a copy of the GNU General Public License and
21// a copy of the GCC Runtime Library Exception along with this program;
22// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23// <http://www.gnu.org/licenses/>.
24
25/** @file debug/deque
26 * This file is a GNU debug extension to the Standard C++ Library.
27 */
28
29#ifndef _GLIBCXX_DEBUG_DEQUE
30#define _GLIBCXX_DEBUG_DEQUE 1
31
32#ifdef _GLIBCXX_SYSHDR
33#pragma GCC system_header
34#endif
35
36#include <bits/c++config.h>
37namespace std _GLIBCXX_VISIBILITY(default) { namespace __debug {
38 template<typename _Tp, typename _Allocator> class deque;
39} } // namespace std::__debug
40
41#include <deque>
42#include <debug/safe_sequence.h>
44#include <debug/safe_iterator.h>
45
46namespace std _GLIBCXX_VISIBILITY(default)
47{
48namespace __debug
49{
50 /// Class std::deque with safety/checking/debug instrumentation.
51 template<typename _Tp, typename _Allocator = std::allocator<_Tp> >
52 class deque
54 deque<_Tp, _Allocator>, _Allocator,
55 __gnu_debug::_Safe_sequence>,
56 public _GLIBCXX_STD_C::deque<_Tp, _Allocator>
57 {
58 typedef _GLIBCXX_STD_C::deque<_Tp, _Allocator> _Base;
60 deque, _Allocator, __gnu_debug::_Safe_sequence> _Safe;
61
62 typedef typename _Base::const_iterator _Base_const_iterator;
63 typedef typename _Base::iterator _Base_iterator;
65
66 template<typename _ItT, typename _SeqT, typename _CatT>
67 friend class ::__gnu_debug::_Safe_iterator;
68
69 // Reference wrapper for base class. Disambiguates deque(const _Base&)
70 // from copy constructor by requiring a user-defined conversion.
71 // See PR libstdc++/90102.
72 struct _Base_ref
73 {
74 _Base_ref(const _Base& __r) : _M_ref(__r) { }
75
76 const _Base& _M_ref;
77 };
78
79 public:
80 typedef typename _Base::reference reference;
81 typedef typename _Base::const_reference const_reference;
82
84 iterator;
86 const_iterator;
87
88 typedef typename _Base::size_type size_type;
89 typedef typename _Base::difference_type difference_type;
90
91 typedef _Tp value_type;
92 typedef _Allocator allocator_type;
93 typedef typename _Base::pointer pointer;
94 typedef typename _Base::const_pointer const_pointer;
95 typedef std::reverse_iterator<iterator> reverse_iterator;
96 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
97
98 // 23.2.1.1 construct/copy/destroy:
99
100#if __cplusplus < 201103L
101 deque()
102 : _Base() { }
103
104 deque(const deque& __x)
105 : _Base(__x) { }
106
107 ~deque() { }
108#else
109 deque() = default;
110 deque(const deque&) = default;
111 deque(deque&&) = default;
112
113 _GLIBCXX26_CONSTEXPR
114 deque(const deque& __d, const __type_identity_t<_Allocator>& __a)
115 : _Base(__d, __a) { }
116
117 _GLIBCXX26_CONSTEXPR
118 deque(deque&& __d, const __type_identity_t<_Allocator>& __a)
119 : _Safe(std::move(__d)), _Base(std::move(__d), __a) { }
120
121 _GLIBCXX26_CONSTEXPR
123 const allocator_type& __a = allocator_type())
124 : _Base(__l, __a) { }
125
126 ~deque() = default;
127#endif
128
129 explicit _GLIBCXX26_CONSTEXPR
130 deque(const _Allocator& __a)
131 : _Base(__a) { }
132
133#if __cplusplus >= 201103L
134 explicit _GLIBCXX26_CONSTEXPR
135 deque(size_type __n, const _Allocator& __a = _Allocator())
136 : _Base(__n, __a) { }
137
138 _GLIBCXX26_CONSTEXPR
139 deque(size_type __n, const __type_identity_t<_Tp>& __value,
140 const _Allocator& __a = _Allocator())
141 : _Base(__n, __value, __a) { }
142#else
143 explicit
144 deque(size_type __n, const _Tp& __value = _Tp(),
145 const _Allocator& __a = _Allocator())
146 : _Base(__n, __value, __a) { }
147#endif
148
149#if __cplusplus >= 201103L
150 template<class _InputIterator,
151 typename = std::_RequireInputIter<_InputIterator>>
152 _GLIBCXX26_CONSTEXPR
153#else
154 template<class _InputIterator>
155#endif
156 deque(_InputIterator __first, _InputIterator __last,
157 const _Allocator& __a = _Allocator())
158 : _Base(__gnu_debug::__base(std::__is_constant_evaluated() ? __first
159 : __glibcxx_check_valid_constructor_range(__first, __last)),
160 __gnu_debug::__base(__last), __a)
161 { }
162
163#if __glibcxx_containers_ranges // C++ >= 23
164 template<__detail::__container_compatible_range<_Tp> _Rg>
165 _GLIBCXX26_CONSTEXPR
166 deque(from_range_t, _Rg&& __rg, const _Allocator& __a = _Allocator())
167 : _Base(from_range, std::forward<_Rg>(__rg), __a)
168 { }
169#endif
170
171 _GLIBCXX26_CONSTEXPR
172 deque(_Base_ref __x)
173 : _Base(__x._M_ref) { }
174
175#if __cplusplus >= 201103L
176 deque&
177 operator=(const deque&) = default;
178
179 deque&
180 operator=(deque&&) = default;
181
182 _GLIBCXX26_CONSTEXPR deque&
183 operator=(initializer_list<value_type> __l)
184 {
185 _Base::operator=(__l);
186 if (!std::__is_constant_evaluated())
187 this->_M_invalidate_all();
188 return *this;
189 }
190#endif
191
192#if __cplusplus >= 201103L
193 template<class _InputIterator,
194 typename = std::_RequireInputIter<_InputIterator>>
195#else
196 template<class _InputIterator>
197#endif
198 _GLIBCXX26_CONSTEXPR void
199 assign(_InputIterator __first, _InputIterator __last)
200 {
201 if (std::__is_constant_evaluated())
202 return _Base::assign(__gnu_debug::__unsafe(__first),
203 __gnu_debug::__unsafe(__last));
204
205 typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
206 __glibcxx_check_valid_range2(__first, __last, __dist);
207 if (__dist.second >= __gnu_debug::__dp_sign)
208 _Base::assign(__gnu_debug::__unsafe(__first),
209 __gnu_debug::__unsafe(__last));
210 else
211 _Base::assign(__first, __last);
212
213 this->_M_invalidate_all();
214 }
215
216 _GLIBCXX26_CONSTEXPR void
217 assign(size_type __n, const _Tp& __t)
218 {
219 _Base::assign(__n, __t);
220 if (!std::__is_constant_evaluated())
221 this->_M_invalidate_all();
222 }
223
224#if __cplusplus >= 201103L
225 _GLIBCXX26_CONSTEXPR void
227 {
228 _Base::assign(__l);
229 if (!std::__is_constant_evaluated())
230 this->_M_invalidate_all();
231 }
232#endif
233
234#if __glibcxx_containers_ranges // C++ >= 23
235 template<std::__detail::__container_compatible_range<_Tp> _Rg>
236 _GLIBCXX26_CONSTEXPR void
237 assign_range(_Rg&& __rg)
238 {
239 _Base::assign_range(std::forward<_Rg>(__rg));
240 if (!std::__is_constant_evaluated())
241 this->_M_invalidate_all();
242 }
243#endif
244
245 using _Base::get_allocator;
246
247 // iterators:
248 _GLIBCXX_NODISCARD
249 _GLIBCXX26_CONSTEXPR iterator
250 begin() _GLIBCXX_NOEXCEPT
251 { return iterator(_Base::begin(), this); }
252
253 _GLIBCXX_NODISCARD
254 _GLIBCXX26_CONSTEXPR const_iterator
255 begin() const _GLIBCXX_NOEXCEPT
256 { return const_iterator(_Base::begin(), this); }
257
258 _GLIBCXX_NODISCARD
259 _GLIBCXX26_CONSTEXPR iterator
260 end() _GLIBCXX_NOEXCEPT
261 { return iterator(_Base::end(), this); }
262
263 _GLIBCXX_NODISCARD
264 _GLIBCXX26_CONSTEXPR const_iterator
265 end() const _GLIBCXX_NOEXCEPT
266 { return const_iterator(_Base::end(), this); }
267
268 _GLIBCXX_NODISCARD
269 _GLIBCXX26_CONSTEXPR reverse_iterator
270 rbegin() _GLIBCXX_NOEXCEPT
271 { return reverse_iterator(end()); }
272
273 _GLIBCXX_NODISCARD
274 _GLIBCXX26_CONSTEXPR const_reverse_iterator
275 rbegin() const _GLIBCXX_NOEXCEPT
276 { return const_reverse_iterator(end()); }
277
278 _GLIBCXX_NODISCARD
279 _GLIBCXX26_CONSTEXPR reverse_iterator
280 rend() _GLIBCXX_NOEXCEPT
281 { return reverse_iterator(begin()); }
282
283 _GLIBCXX_NODISCARD
284 _GLIBCXX26_CONSTEXPR const_reverse_iterator
285 rend() const _GLIBCXX_NOEXCEPT
286 { return const_reverse_iterator(begin()); }
287
288#if __cplusplus >= 201103L
289 [[__nodiscard__]]
290 _GLIBCXX26_CONSTEXPR const_iterator
291 cbegin() const noexcept
292 { return const_iterator(_Base::begin(), this); }
293
294 [[__nodiscard__]]
295 _GLIBCXX26_CONSTEXPR const_iterator
296 cend() const noexcept
297 { return const_iterator(_Base::end(), this); }
298
299 [[__nodiscard__]]
300 _GLIBCXX26_CONSTEXPR const_reverse_iterator
301 crbegin() const noexcept
302 { return const_reverse_iterator(end()); }
303
304 [[__nodiscard__]]
305 _GLIBCXX26_CONSTEXPR const_reverse_iterator
306 crend() const noexcept
307 { return const_reverse_iterator(begin()); }
308#endif
309
310 private:
311 _GLIBCXX26_CONSTEXPR void
312 _M_invalidate_after_nth(difference_type __n)
313 {
315 this->_M_invalidate_if(_After_nth(__n, _Base::begin()));
316 }
317
318 public:
319 // 23.2.1.2 capacity:
320 using _Base::size;
321 using _Base::max_size;
322
323#if __cplusplus >= 201103L
324 _GLIBCXX26_CONSTEXPR void
325 resize(size_type __sz)
326 {
327 if (std::__is_constant_evaluated())
328 return _Base::resize(__sz);
329
330 bool __invalidate_all = __sz > this->size();
331 if (__sz < this->size())
332 this->_M_invalidate_after_nth(__sz);
333
334 _Base::resize(__sz);
335
336 if (__invalidate_all)
337 this->_M_invalidate_all();
338 }
339
340 _GLIBCXX26_CONSTEXPR void
341 resize(size_type __sz, const _Tp& __c)
342 {
343 if (std::__is_constant_evaluated())
344 return _Base::resize(__sz, __c);
345
346 bool __invalidate_all = __sz > this->size();
347 if (__sz < this->size())
348 this->_M_invalidate_after_nth(__sz);
349
350 _Base::resize(__sz, __c);
351
352 if (__invalidate_all)
353 this->_M_invalidate_all();
354 }
355#else
356 void
357 resize(size_type __sz, _Tp __c = _Tp())
358 {
359 bool __invalidate_all = __sz > this->size();
360 if (__sz < this->size())
361 this->_M_invalidate_after_nth(__sz);
362
363 _Base::resize(__sz, __c);
364
365 if (__invalidate_all)
366 this->_M_invalidate_all();
367 }
368#endif
369
370#if __cplusplus >= 201103L
371 _GLIBCXX26_CONSTEXPR void
372 shrink_to_fit() noexcept
373 {
374 if (_Base::_M_shrink_to_fit())
375 if (!std::__is_constant_evaluated())
376 this->_M_invalidate_all();
377 }
378#endif
379
380 using _Base::empty;
381
382 // element access:
383 _GLIBCXX_NODISCARD
384 _GLIBCXX26_CONSTEXPR reference
385 operator[](size_type __n) _GLIBCXX_NOEXCEPT
386 {
387 __glibcxx_check_subscript(__n);
388 return _Base::operator[](__n);
389 }
390
391 _GLIBCXX_NODISCARD
392 _GLIBCXX26_CONSTEXPR const_reference
393 operator[](size_type __n) const _GLIBCXX_NOEXCEPT
394 {
395 __glibcxx_check_subscript(__n);
396 return _Base::operator[](__n);
397 }
398
399 using _Base::at;
400
401 _GLIBCXX_NODISCARD
402 _GLIBCXX26_CONSTEXPR reference
403 front() _GLIBCXX_NOEXCEPT
404 {
405 __glibcxx_check_nonempty();
406 return _Base::front();
407 }
408
409 _GLIBCXX_NODISCARD
410 _GLIBCXX26_CONSTEXPR const_reference
411 front() const _GLIBCXX_NOEXCEPT
412 {
413 __glibcxx_check_nonempty();
414 return _Base::front();
415 }
416
417 _GLIBCXX_NODISCARD
418 _GLIBCXX26_CONSTEXPR reference
419 back() _GLIBCXX_NOEXCEPT
420 {
421 __glibcxx_check_nonempty();
422 return _Base::back();
423 }
424
425 _GLIBCXX_NODISCARD
426 _GLIBCXX26_CONSTEXPR const_reference
427 back() const _GLIBCXX_NOEXCEPT
428 {
429 __glibcxx_check_nonempty();
430 return _Base::back();
431 }
432
433 // 23.2.1.3 modifiers:
434 _GLIBCXX26_CONSTEXPR void
435 push_front(const _Tp& __x)
436 {
437 _Base::push_front(__x);
438 this->_M_invalidate_all();
439 }
440
441 _GLIBCXX26_CONSTEXPR void
442 push_back(const _Tp& __x)
443 {
444 _Base::push_back(__x);
445 this->_M_invalidate_all();
446 }
447
448#if __cplusplus >= 201103L
449 _GLIBCXX26_CONSTEXPR void
450 push_front(_Tp&& __x)
451 { emplace_front(std::move(__x)); }
452
453 _GLIBCXX26_CONSTEXPR void
454 push_back(_Tp&& __x)
455 { emplace_back(std::move(__x)); }
456
457 template<typename... _Args>
458#if __cplusplus > 201402L
459 _GLIBCXX26_CONSTEXPR reference
460#else
461 void
462#endif
463 emplace_front(_Args&&... __args)
464 {
465 _Base::emplace_front(std::forward<_Args>(__args)...);
466 if (!std::__is_constant_evaluated())
467 this->_M_invalidate_all();
468#if __cplusplus > 201402L
469 return front();
470#endif
471 }
472
473 template<typename... _Args>
474#if __cplusplus > 201402L
475 _GLIBCXX26_CONSTEXPR reference
476#else
477 void
478#endif
479 emplace_back(_Args&&... __args)
480 {
481 _Base::emplace_back(std::forward<_Args>(__args)...);
482 if (!std::__is_constant_evaluated())
483 this->_M_invalidate_all();
484#if __cplusplus > 201402L
485 return back();
486#endif
487 }
488
489 template<typename... _Args>
490 _GLIBCXX26_CONSTEXPR iterator
491 emplace(const_iterator __position, _Args&&... __args)
492 {
493 if (std::__is_constant_evaluated())
494 return iterator(_Base::emplace(__position.base(),
495 std::forward<_Args>(__args)...),
496 this);
497
498 __glibcxx_check_insert(__position);
499 _Base_iterator __res = _Base::emplace(__position.base(),
500 std::forward<_Args>(__args)...);
501 this->_M_invalidate_all();
502 return iterator(__res, this);
503 }
504#endif
505
506 _GLIBCXX26_CONSTEXPR iterator
507#if __cplusplus >= 201103L
508 insert(const_iterator __position, const _Tp& __x)
509#else
510 insert(iterator __position, const _Tp& __x)
511#endif
512 {
513 if (std::__is_constant_evaluated())
514 return iterator(_Base::insert(__position.base(), __x), this);
515
516 __glibcxx_check_insert(__position);
517 _Base_iterator __res = _Base::insert(__position.base(), __x);
518 this->_M_invalidate_all();
519 return iterator(__res, this);
520 }
521
522#if __cplusplus >= 201103L
523 _GLIBCXX26_CONSTEXPR iterator
524 insert(const_iterator __position, _Tp&& __x)
525 { return emplace(__position, std::move(__x)); }
526
527 _GLIBCXX26_CONSTEXPR iterator
528 insert(const_iterator __position, initializer_list<value_type> __l)
529 {
530 if (std::__is_constant_evaluated())
531 return iterator(_Base::insert(__position.base(), __l), this);
532
533 __glibcxx_check_insert(__position);
534 _Base_iterator __res = _Base::insert(__position.base(), __l);
535 this->_M_invalidate_all();
536 return iterator(__res, this);
537 }
538#endif
539
540#if __cplusplus >= 201103L
541 _GLIBCXX26_CONSTEXPR iterator
542 insert(const_iterator __position, size_type __n, const _Tp& __x)
543 {
544 if (std::__is_constant_evaluated())
545 return iterator(_Base::insert(__position.base(), __n, __x), this);
546
547 __glibcxx_check_insert(__position);
548 _Base_iterator __res = _Base::insert(__position.base(), __n, __x);
549 this->_M_invalidate_all();
550 return iterator(__res, this);
551 }
552#else
553 void
554 insert(iterator __position, size_type __n, const _Tp& __x)
555 {
556 __glibcxx_check_insert(__position);
557 _Base::insert(__position.base(), __n, __x);
558 this->_M_invalidate_all();
559 }
560#endif
561
562#if __cplusplus >= 201103L
563 template<class _InputIterator,
564 typename = std::_RequireInputIter<_InputIterator>>
565 _GLIBCXX26_CONSTEXPR iterator
566 insert(const_iterator __position,
567 _InputIterator __first, _InputIterator __last)
568 {
569 if (std::__is_constant_evaluated())
570 return iterator(_Base::insert(__position.base(),
571 __gnu_debug::__unsafe(__first),
572 __gnu_debug::__unsafe(__last)), this);
573
574 typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
575 __glibcxx_check_insert_range(__position, __first, __last, __dist);
576 _Base_iterator __res;
577 if (__dist.second >= __gnu_debug::__dp_sign)
578 __res = _Base::insert(__position.base(),
579 __gnu_debug::__unsafe(__first),
580 __gnu_debug::__unsafe(__last));
581 else
582 __res = _Base::insert(__position.base(), __first, __last);
583
584 this->_M_invalidate_all();
585 return iterator(__res, this);
586 }
587#else
588 template<class _InputIterator>
589 void
590 insert(iterator __position,
591 _InputIterator __first, _InputIterator __last)
592 {
593 typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
594 __glibcxx_check_insert_range(__position, __first, __last, __dist);
595
596 if (__dist.second >= __gnu_debug::__dp_sign)
597 _Base::insert(__position.base(),
598 __gnu_debug::__unsafe(__first),
599 __gnu_debug::__unsafe(__last));
600 else
601 _Base::insert(__position.base(), __first, __last);
602
603 this->_M_invalidate_all();
604 }
605#endif
606
607#if __glibcxx_containers_ranges // C++ >= 23
608 template<__detail::__container_compatible_range<_Tp> _Rg>
609 _GLIBCXX26_CONSTEXPR iterator
610 insert_range(const_iterator __pos, _Rg&& __rg)
611 {
612 auto __res = _Base::insert_range(__pos.base(), std::forward<_Rg>(__rg));
613 if (!std::__is_constant_evaluated())
614 this->_M_invalidate_all();
615 return iterator(__res, this);
616 }
617
618 template<std::__detail::__container_compatible_range<_Tp> _Rg>
619 _GLIBCXX26_CONSTEXPR void
620 prepend_range(_Rg&& __rg)
621 {
622 _Base::prepend_range(std::forward<_Rg>(__rg));
623 if (!std::__is_constant_evaluated())
624 this->_M_invalidate_all();
625 }
626
627 template<std::__detail::__container_compatible_range<_Tp> _Rg>
628 _GLIBCXX26_CONSTEXPR void
629 append_range(_Rg&& __rg)
630 {
631 _Base::append_range(std::forward<_Rg>(__rg));
632 if (!std::__is_constant_evaluated())
633 this->_M_invalidate_all();
634 }
635#endif
636
637 _GLIBCXX26_CONSTEXPR void
638 pop_front() _GLIBCXX_NOEXCEPT
639 {
640 if (!std::__is_constant_evaluated())
641 {
642 __glibcxx_check_nonempty();
643 this->_M_invalidate_if(_Equal(_Base::begin()));
644 }
645 _Base::pop_front();
646 }
647
648 _GLIBCXX26_CONSTEXPR void
649 pop_back() _GLIBCXX_NOEXCEPT
650 {
651 if (!std::__is_constant_evaluated())
652 {
653 __glibcxx_check_nonempty();
654 this->_M_invalidate_if(_Equal(_Base::begin()));
655 }
656 _Base::pop_back();
657 }
658
659 _GLIBCXX26_CONSTEXPR iterator
660#if __cplusplus >= 201103L
661 erase(const_iterator __position)
662#else
663 erase(iterator __position)
664#endif
665 {
666 if (std::__is_constant_evaluated())
667 return iterator(_Base::erase(__position.base()), this);
668
669 __glibcxx_check_erase(__position);
670#if __cplusplus >= 201103L
671 _Base_const_iterator __victim = __position.base();
672#else
673 _Base_iterator __victim = __position.base();
674#endif
675 if (__victim == _Base::begin() || __victim == _Base::end() - 1)
676 {
677 this->_M_invalidate_if(_Equal(__victim));
678 return iterator(_Base::erase(__victim), this);
679 }
680 else
681 {
682 _Base_iterator __res = _Base::erase(__victim);
683 this->_M_invalidate_all();
684 return iterator(__res, this);
685 }
686 }
687
688 _GLIBCXX26_CONSTEXPR iterator
689#if __cplusplus >= 201103L
690 erase(const_iterator __first, const_iterator __last)
691#else
692 erase(iterator __first, iterator __last)
693#endif
694 {
695 if (std::__is_constant_evaluated())
696 return iterator(_Base::erase(__first.base(), __last.base()), this);
697
698 // _GLIBCXX_RESOLVE_LIB_DEFECTS
699 // 151. can't currently clear() empty container
700 __glibcxx_check_erase_range(__first, __last);
701
702 if (__first.base() == __last.base())
703#if __cplusplus >= 201103L
704 return iterator(__first.base()._M_const_cast(), this);
705#else
706 return __first;
707#endif
708 else if (__first.base() == _Base::begin()
709 || __last.base() == _Base::end())
710 {
711 const deque* __this = this;
712 __this->_M_detach_singular();
713 for (_Base_const_iterator __position = __first.base();
714 __position != __last.base(); ++__position)
715 {
716 this->_M_invalidate_if(_Equal(__position));
717 }
718 __try
719 {
720 return iterator(_Base::erase(__first.base(), __last.base()),
721 this);
722 }
723 __catch(...)
724 {
725 __this->_M_revalidate_singular();
726 __throw_exception_again;
727 }
728 }
729 else
730 {
731 _Base_iterator __res = _Base::erase(__first.base(),
732 __last.base());
733 this->_M_invalidate_all();
734 return iterator(__res, this);
735 }
736 }
737
738 _GLIBCXX26_CONSTEXPR void
739 swap(deque& __x)
740 _GLIBCXX_NOEXCEPT_IF( noexcept(declval<_Base&>().swap(__x)) )
741 {
742 if (!std::__is_constant_evaluated())
743 _Safe::_M_swap(__x);
744 _Base::swap(__x);
745 }
746
747 _GLIBCXX26_CONSTEXPR void
748 clear() _GLIBCXX_NOEXCEPT
749 {
750 _Base::clear();
751 if (!std::__is_constant_evaluated())
752 this->_M_invalidate_all();
753 }
754
755 _GLIBCXX26_CONSTEXPR _Base&
756 _M_base() _GLIBCXX_NOEXCEPT { return *this; }
757
758 _GLIBCXX26_CONSTEXPR const _Base&
759 _M_base() const _GLIBCXX_NOEXCEPT { return *this; }
760 };
761
762#if __cpp_deduction_guides >= 201606
763 template<typename _InputIterator, typename _ValT
765 typename _Allocator = allocator<_ValT>,
766 typename = _RequireInputIter<_InputIterator>,
767 typename = _RequireAllocator<_Allocator>>
768 deque(_InputIterator, _InputIterator, _Allocator = _Allocator())
770
771 template<typename _Tp, typename _Allocator = allocator<_Tp>,
772 typename = _RequireAllocator<_Allocator>>
773 deque(size_t, _Tp, _Allocator = _Allocator())
775
776#if __glibcxx_containers_ranges // C++ >= 23
777 template<ranges::input_range _Rg,
778 __allocator_like _Alloc = allocator<ranges::range_value_t<_Rg>>>
779 deque(from_range_t, _Rg&&, _Alloc = _Alloc())
781#endif
782#endif
783
784 template<typename _Tp, typename _Alloc>
785 inline _GLIBCXX26_CONSTEXPR bool
786 operator==(const deque<_Tp, _Alloc>& __lhs,
787 const deque<_Tp, _Alloc>& __rhs)
788 { return __lhs._M_base() == __rhs._M_base(); }
789
790#if __cpp_lib_three_way_comparison
791 template<typename _Tp, typename _Alloc>
792 constexpr __detail::__synth3way_t<_Tp>
793 operator<=>(const deque<_Tp, _Alloc>& __x, const deque<_Tp, _Alloc>& __y)
794 { return __x._M_base() <=> __y._M_base(); }
795#else
796 template<typename _Tp, typename _Alloc>
797 inline bool
798 operator!=(const deque<_Tp, _Alloc>& __lhs,
799 const deque<_Tp, _Alloc>& __rhs)
800 { return __lhs._M_base() != __rhs._M_base(); }
801
802 template<typename _Tp, typename _Alloc>
803 inline bool
804 operator<(const deque<_Tp, _Alloc>& __lhs,
805 const deque<_Tp, _Alloc>& __rhs)
806 { return __lhs._M_base() < __rhs._M_base(); }
807
808 template<typename _Tp, typename _Alloc>
809 inline bool
810 operator<=(const deque<_Tp, _Alloc>& __lhs,
811 const deque<_Tp, _Alloc>& __rhs)
812 { return __lhs._M_base() <= __rhs._M_base(); }
813
814 template<typename _Tp, typename _Alloc>
815 inline bool
816 operator>=(const deque<_Tp, _Alloc>& __lhs,
817 const deque<_Tp, _Alloc>& __rhs)
818 { return __lhs._M_base() >= __rhs._M_base(); }
819
820 template<typename _Tp, typename _Alloc>
821 inline bool
822 operator>(const deque<_Tp, _Alloc>& __lhs,
823 const deque<_Tp, _Alloc>& __rhs)
824 { return __lhs._M_base() > __rhs._M_base(); }
825#endif // three-way comparison
826
827 template<typename _Tp, typename _Alloc>
828 inline _GLIBCXX26_CONSTEXPR void
829 swap(deque<_Tp, _Alloc>& __lhs, deque<_Tp, _Alloc>& __rhs)
830 _GLIBCXX_NOEXCEPT_IF(noexcept(__lhs.swap(__rhs)))
831 { __lhs.swap(__rhs); }
832
833} // namespace __debug
834
835#ifdef __glibcxx_erase_if // C++ >= 20 && HOSTED
836_GLIBCXX_BEGIN_NAMESPACE_VERSION
837 template<typename _Tp, typename _Alloc, typename _Predicate>
838 inline _GLIBCXX26_CONSTEXPR typename __debug::deque<_Tp, _Alloc>::size_type
839 erase_if(__debug::deque<_Tp, _Alloc>& __cont, _Predicate __pred)
840 {
841 return __detail::__erase_if(__cont, __cont._M_base(), std::move(__pred));
842 }
843
844 template<typename _Tp, typename _Alloc, typename _Up = _Tp>
845 inline _GLIBCXX26_CONSTEXPR typename __debug::deque<_Tp, _Alloc>::size_type
846 erase(__debug::deque<_Tp, _Alloc>& __cont, const _Up& __value)
847 { return std::erase_if(__cont, __gnu_cxx::__ops::__equal_to(__value)); }
848_GLIBCXX_END_NAMESPACE_VERSION
849#endif // __glibcxx_erase_if
850} // namespace std
851
852#endif
#define __glibcxx_check_insert(_Position)
Definition macros.h:143
#define __glibcxx_check_erase_range(_First, _Last)
Definition macros.h:245
#define __glibcxx_check_erase(_Position)
Definition macros.h:209
#define __glibcxx_check_insert_range(_Position, _First, _Last, _Dist)
Definition macros.h:177
constexpr bool operator<=(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
Definition chrono.h:863
constexpr bool operator>=(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
Definition chrono.h:877
constexpr bool operator<(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
Definition chrono.h:830
constexpr bool operator>(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
Definition chrono.h:870
auto declval() noexcept -> decltype(__declval< _Tp >(0))
Definition type_traits:2741
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
Definition move.h:138
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
Definition move.h:72
ISO C++ entities toplevel namespace is std.
constexpr auto size(const _Container &__cont) noexcept(noexcept(__cont.size())) -> decltype(__cont.size())
Return the size of a container.
constexpr _Iterator __base(_Iterator __it)
GNU debug code, replaces standard behavior with debug behavior.
initializer_list
The standard allocator, as per C++03 [20.4.1].
Definition allocator.h:134
Safe iterator wrapper.
constexpr _Iterator & base() noexcept
Return the underlying iterator.
Traits class for iterators.
A standard container using fixed-size memory allocation and constant-time manipulation of elements at...
Definition stl_deque.h:854
Base class for constructing a safe sequence type that tracks iterators that reference it.
Safe class dealing with some allocator dependent operations.
Class std::deque with safety/checking/debug instrumentation.
Definition debug/deque:57
A range for which ranges::begin returns an input iterator.