]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/include/debug/deque
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / include / debug / deque
CommitLineData
285b36d6
BK
1// Debugging deque implementation -*- C++ -*-
2
7adcbafe 3// Copyright (C) 2003-2022 Free Software Foundation, Inc.
285b36d6
BK
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
748086b7 8// Free Software Foundation; either version 3, or (at your option)
285b36d6
BK
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
748086b7
JJ
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/>.
285b36d6 24
78a53887
BK
25/** @file debug/deque
26 * This file is a GNU debug extension to the Standard C++ Library.
27 */
28
285b36d6
BK
29#ifndef _GLIBCXX_DEBUG_DEQUE
30#define _GLIBCXX_DEBUG_DEQUE 1
31
541a9b10
JW
32#pragma GCC system_header
33
9ca2ac69
JW
34#include <bits/c++config.h>
35namespace std _GLIBCXX_VISIBILITY(default) { namespace __debug {
36 template<typename _Tp, typename _Allocator> class deque;
37} } // namespace std::__debug
38
285b36d6
BK
39#include <deque>
40#include <debug/safe_sequence.h>
15ee1a77 41#include <debug/safe_container.h>
285b36d6
BK
42#include <debug/safe_iterator.h>
43
12ffa228 44namespace std _GLIBCXX_VISIBILITY(default)
3cbc7af0 45{
45f388bb 46namespace __debug
285b36d6 47{
1ceb9e06 48 /// Class std::deque with safety/checking/debug instrumentation.
285b36d6 49 template<typename _Tp, typename _Allocator = std::allocator<_Tp> >
526da49c 50 class deque
15ee1a77
FD
51 : public __gnu_debug::_Safe_container<
52 deque<_Tp, _Allocator>, _Allocator,
b6f86694 53 __gnu_debug::_Safe_sequence>,
15ee1a77 54 public _GLIBCXX_STD_C::deque<_Tp, _Allocator>
285b36d6 55 {
15ee1a77
FD
56 typedef _GLIBCXX_STD_C::deque<_Tp, _Allocator> _Base;
57 typedef __gnu_debug::_Safe_container<
b6f86694 58 deque, _Allocator, __gnu_debug::_Safe_sequence> _Safe;
285b36d6 59
15ee1a77
FD
60 typedef typename _Base::const_iterator _Base_const_iterator;
61 typedef typename _Base::iterator _Base_iterator;
afe96d41 62 typedef __gnu_debug::_Equal_to<_Base_const_iterator> _Equal;
15ee1a77 63
e9afbed0
FD
64 template<typename _ItT, typename _SeqT, typename _CatT>
65 friend class ::__gnu_debug::_Safe_iterator;
66
eca833b8
JW
67 // Reference wrapper for base class. Disambiguates deque(const _Base&)
68 // from copy constructor by requiring a user-defined conversion.
69 // See PR libstdc++/90102.
70 struct _Base_ref
71 {
72 _Base_ref(const _Base& __r) : _M_ref(__r) { }
73
74 const _Base& _M_ref;
75 };
76
285b36d6 77 public:
15ee1a77
FD
78 typedef typename _Base::reference reference;
79 typedef typename _Base::const_reference const_reference;
526da49c 80
15ee1a77
FD
81 typedef __gnu_debug::_Safe_iterator<_Base_iterator, deque>
82 iterator;
83 typedef __gnu_debug::_Safe_iterator<_Base_const_iterator, deque>
84 const_iterator;
526da49c 85
15ee1a77
FD
86 typedef typename _Base::size_type size_type;
87 typedef typename _Base::difference_type difference_type;
526da49c 88
15ee1a77
FD
89 typedef _Tp value_type;
90 typedef _Allocator allocator_type;
91 typedef typename _Base::pointer pointer;
92 typedef typename _Base::const_pointer const_pointer;
93 typedef std::reverse_iterator<iterator> reverse_iterator;
94 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
285b36d6
BK
95
96 // 23.2.1.1 construct/copy/destroy:
c3cdd71f 97
15ee1a77
FD
98#if __cplusplus < 201103L
99 deque()
100 : _Base() { }
101
102 deque(const deque& __x)
103 : _Base(__x) { }
104
105 ~deque() { }
106#else
107 deque() = default;
108 deque(const deque&) = default;
109 deque(deque&&) = default;
110
22d34a2a 111 deque(const deque& __d, const __type_identity_t<_Allocator>& __a)
fd18c76a
JW
112 : _Base(__d, __a) { }
113
22d34a2a 114 deque(deque&& __d, const __type_identity_t<_Allocator>& __a)
fd18c76a
JW
115 : _Safe(std::move(__d)), _Base(std::move(__d), __a) { }
116
15ee1a77
FD
117 deque(initializer_list<value_type> __l,
118 const allocator_type& __a = allocator_type())
119 : _Base(__l, __a) { }
120
121 ~deque() = default;
122#endif
c3cdd71f 123
dc2cf706 124 explicit
c3cdd71f 125 deque(const _Allocator& __a)
285b36d6
BK
126 : _Base(__a) { }
127
734f5023 128#if __cplusplus >= 201103L
dc2cf706 129 explicit
fd18c76a
JW
130 deque(size_type __n, const _Allocator& __a = _Allocator())
131 : _Base(__n, __a) { }
dc2cf706 132
085c2f8f 133 deque(size_type __n, const __type_identity_t<_Tp>& __value,
dc2cf706
PC
134 const _Allocator& __a = _Allocator())
135 : _Base(__n, __value, __a) { }
136#else
137 explicit
138 deque(size_type __n, const _Tp& __value = _Tp(),
139 const _Allocator& __a = _Allocator())
285b36d6 140 : _Base(__n, __value, __a) { }
dc2cf706 141#endif
285b36d6 142
734f5023 143#if __cplusplus >= 201103L
2203cb90
PC
144 template<class _InputIterator,
145 typename = std::_RequireInputIter<_InputIterator>>
146#else
285b36d6 147 template<class _InputIterator>
2203cb90 148#endif
15ee1a77 149 deque(_InputIterator __first, _InputIterator __last,
285b36d6 150 const _Allocator& __a = _Allocator())
90aabc7e
FD
151 : _Base(__gnu_debug::__base(
152 __glibcxx_check_valid_constructor_range(__first, __last)),
1f5ca1a1 153 __gnu_debug::__base(__last), __a)
15ee1a77 154 { }
285b36d6 155
eca833b8
JW
156 deque(_Base_ref __x)
157 : _Base(__x._M_ref) { }
ed540c0a 158
4a407d35 159#if __cplusplus >= 201103L
15ee1a77
FD
160 deque&
161 operator=(const deque&) = default;
526da49c 162
ed540c0a 163 deque&
15ee1a77 164 operator=(deque&&) = default;
988499f4
JM
165
166 deque&
167 operator=(initializer_list<value_type> __l)
168 {
e9a53a4f 169 _Base::operator=(__l);
988499f4
JM
170 this->_M_invalidate_all();
171 return *this;
172 }
ed540c0a
CJ
173#endif
174
734f5023 175#if __cplusplus >= 201103L
2203cb90
PC
176 template<class _InputIterator,
177 typename = std::_RequireInputIter<_InputIterator>>
178#else
285b36d6 179 template<class _InputIterator>
2203cb90 180#endif
15ee1a77
FD
181 void
182 assign(_InputIterator __first, _InputIterator __last)
183 {
24167c42
FD
184 typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
185 __glibcxx_check_valid_range2(__first, __last, __dist);
186 if (__dist.second >= __gnu_debug::__dp_sign)
187 _Base::assign(__gnu_debug::__unsafe(__first),
188 __gnu_debug::__unsafe(__last));
189 else
190 _Base::assign(__first, __last);
191
285b36d6
BK
192 this->_M_invalidate_all();
193 }
194
526da49c 195 void
285b36d6
BK
196 assign(size_type __n, const _Tp& __t)
197 {
198 _Base::assign(__n, __t);
199 this->_M_invalidate_all();
200 }
526da49c 201
734f5023 202#if __cplusplus >= 201103L
988499f4
JM
203 void
204 assign(initializer_list<value_type> __l)
205 {
206 _Base::assign(__l);
207 this->_M_invalidate_all();
208 }
209#endif
210
285b36d6 211 using _Base::get_allocator;
526da49c 212
285b36d6 213 // iterators:
0d04fe49 214 _GLIBCXX_NODISCARD
526da49c 215 iterator
d3677132 216 begin() _GLIBCXX_NOEXCEPT
285b36d6 217 { return iterator(_Base::begin(), this); }
526da49c 218
0d04fe49 219 _GLIBCXX_NODISCARD
526da49c 220 const_iterator
d3677132 221 begin() const _GLIBCXX_NOEXCEPT
285b36d6 222 { return const_iterator(_Base::begin(), this); }
526da49c 223
0d04fe49 224 _GLIBCXX_NODISCARD
526da49c 225 iterator
d3677132 226 end() _GLIBCXX_NOEXCEPT
285b36d6 227 { return iterator(_Base::end(), this); }
526da49c 228
0d04fe49 229 _GLIBCXX_NODISCARD
526da49c 230 const_iterator
d3677132 231 end() const _GLIBCXX_NOEXCEPT
285b36d6 232 { return const_iterator(_Base::end(), this); }
526da49c 233
0d04fe49 234 _GLIBCXX_NODISCARD
526da49c 235 reverse_iterator
d3677132 236 rbegin() _GLIBCXX_NOEXCEPT
285b36d6 237 { return reverse_iterator(end()); }
526da49c 238
0d04fe49 239 _GLIBCXX_NODISCARD
526da49c 240 const_reverse_iterator
d3677132 241 rbegin() const _GLIBCXX_NOEXCEPT
285b36d6 242 { return const_reverse_iterator(end()); }
526da49c 243
0d04fe49 244 _GLIBCXX_NODISCARD
526da49c 245 reverse_iterator
d3677132 246 rend() _GLIBCXX_NOEXCEPT
285b36d6 247 { return reverse_iterator(begin()); }
526da49c 248
0d04fe49 249 _GLIBCXX_NODISCARD
526da49c 250 const_reverse_iterator
d3677132 251 rend() const _GLIBCXX_NOEXCEPT
285b36d6 252 { return const_reverse_iterator(begin()); }
526da49c 253
734f5023 254#if __cplusplus >= 201103L
0d04fe49 255 [[__nodiscard__]]
0cd50f89 256 const_iterator
d3677132 257 cbegin() const noexcept
0cd50f89
PC
258 { return const_iterator(_Base::begin(), this); }
259
0d04fe49 260 [[__nodiscard__]]
0cd50f89 261 const_iterator
d3677132 262 cend() const noexcept
0cd50f89
PC
263 { return const_iterator(_Base::end(), this); }
264
0d04fe49 265 [[__nodiscard__]]
0cd50f89 266 const_reverse_iterator
d3677132 267 crbegin() const noexcept
0cd50f89
PC
268 { return const_reverse_iterator(end()); }
269
0d04fe49 270 [[__nodiscard__]]
0cd50f89 271 const_reverse_iterator
d3677132 272 crend() const noexcept
0cd50f89
PC
273 { return const_reverse_iterator(begin()); }
274#endif
275
afe96d41
FD
276 private:
277 void
278 _M_invalidate_after_nth(difference_type __n)
279 {
280 typedef __gnu_debug::_After_nth_from<_Base_const_iterator> _After_nth;
281 this->_M_invalidate_if(_After_nth(__n, _Base::begin()));
282 }
15ee1a77 283
afe96d41 284 public:
285b36d6
BK
285 // 23.2.1.2 capacity:
286 using _Base::size;
287 using _Base::max_size;
526da49c 288
734f5023 289#if __cplusplus >= 201103L
dc2cf706
PC
290 void
291 resize(size_type __sz)
292 {
dc2cf706
PC
293 bool __invalidate_all = __sz > this->size();
294 if (__sz < this->size())
afe96d41 295 this->_M_invalidate_after_nth(__sz);
dc2cf706
PC
296
297 _Base::resize(__sz);
298
299 if (__invalidate_all)
300 this->_M_invalidate_all();
301 }
302
303 void
304 resize(size_type __sz, const _Tp& __c)
305 {
dc2cf706
PC
306 bool __invalidate_all = __sz > this->size();
307 if (__sz < this->size())
afe96d41 308 this->_M_invalidate_after_nth(__sz);
dc2cf706
PC
309
310 _Base::resize(__sz, __c);
311
312 if (__invalidate_all)
313 this->_M_invalidate_all();
314 }
315#else
526da49c 316 void
285b36d6
BK
317 resize(size_type __sz, _Tp __c = _Tp())
318 {
285b36d6
BK
319 bool __invalidate_all = __sz > this->size();
320 if (__sz < this->size())
afe96d41 321 this->_M_invalidate_after_nth(__sz);
526da49c 322
285b36d6 323 _Base::resize(__sz, __c);
526da49c 324
285b36d6
BK
325 if (__invalidate_all)
326 this->_M_invalidate_all();
327 }
dc2cf706 328#endif
526da49c 329
734f5023 330#if __cplusplus >= 201103L
8a752dfe 331 void
d15ac9d9 332 shrink_to_fit() noexcept
8a752dfe
FD
333 {
334 if (_Base::_M_shrink_to_fit())
335 this->_M_invalidate_all();
336 }
79667f82
PC
337#endif
338
285b36d6 339 using _Base::empty;
526da49c 340
285b36d6 341 // element access:
0d04fe49 342 _GLIBCXX_NODISCARD
526da49c 343 reference
d15ac9d9 344 operator[](size_type __n) _GLIBCXX_NOEXCEPT
285b36d6
BK
345 {
346 __glibcxx_check_subscript(__n);
e9a53a4f 347 return _Base::operator[](__n);
285b36d6 348 }
526da49c 349
0d04fe49 350 _GLIBCXX_NODISCARD
526da49c 351 const_reference
d15ac9d9 352 operator[](size_type __n) const _GLIBCXX_NOEXCEPT
285b36d6
BK
353 {
354 __glibcxx_check_subscript(__n);
e9a53a4f 355 return _Base::operator[](__n);
285b36d6 356 }
526da49c 357
285b36d6 358 using _Base::at;
526da49c 359
0d04fe49 360 _GLIBCXX_NODISCARD
526da49c 361 reference
d15ac9d9 362 front() _GLIBCXX_NOEXCEPT
285b36d6
BK
363 {
364 __glibcxx_check_nonempty();
365 return _Base::front();
366 }
526da49c 367
0d04fe49 368 _GLIBCXX_NODISCARD
526da49c 369 const_reference
d15ac9d9 370 front() const _GLIBCXX_NOEXCEPT
285b36d6
BK
371 {
372 __glibcxx_check_nonempty();
373 return _Base::front();
374 }
526da49c 375
0d04fe49 376 _GLIBCXX_NODISCARD
526da49c 377 reference
d15ac9d9 378 back() _GLIBCXX_NOEXCEPT
285b36d6
BK
379 {
380 __glibcxx_check_nonempty();
381 return _Base::back();
382 }
526da49c 383
0d04fe49 384 _GLIBCXX_NODISCARD
526da49c 385 const_reference
d15ac9d9 386 back() const _GLIBCXX_NOEXCEPT
285b36d6
BK
387 {
388 __glibcxx_check_nonempty();
389 return _Base::back();
390 }
526da49c 391
285b36d6 392 // 23.2.1.3 modifiers:
526da49c 393 void
285b36d6
BK
394 push_front(const _Tp& __x)
395 {
396 _Base::push_front(__x);
397 this->_M_invalidate_all();
398 }
526da49c
BI
399
400 void
285b36d6
BK
401 push_back(const _Tp& __x)
402 {
403 _Base::push_back(__x);
404 this->_M_invalidate_all();
405 }
4dc3e453 406
734f5023 407#if __cplusplus >= 201103L
4dc3e453
PC
408 void
409 push_front(_Tp&& __x)
410 { emplace_front(std::move(__x)); }
411
412 void
413 push_back(_Tp&& __x)
414 { emplace_back(std::move(__x)); }
415
7ffec97f 416 template<typename... _Args>
594ef205
JW
417#if __cplusplus > 201402L
418 reference
419#else
15ee1a77 420 void
594ef205 421#endif
15ee1a77 422 emplace_front(_Args&&... __args)
7ffec97f 423 {
4dc3e453 424 _Base::emplace_front(std::forward<_Args>(__args)...);
7ffec97f 425 this->_M_invalidate_all();
594ef205
JW
426#if __cplusplus > 201402L
427 return front();
428#endif
7ffec97f
CJ
429 }
430
431 template<typename... _Args>
594ef205
JW
432#if __cplusplus > 201402L
433 reference
434#else
15ee1a77 435 void
594ef205 436#endif
15ee1a77 437 emplace_back(_Args&&... __args)
7ffec97f 438 {
4dc3e453 439 _Base::emplace_back(std::forward<_Args>(__args)...);
7ffec97f 440 this->_M_invalidate_all();
594ef205
JW
441#if __cplusplus > 201402L
442 return back();
443#endif
7ffec97f
CJ
444 }
445
446 template<typename... _Args>
15ee1a77
FD
447 iterator
448 emplace(const_iterator __position, _Args&&... __args)
7ffec97f
CJ
449 {
450 __glibcxx_check_insert(__position);
afe96d41
FD
451 _Base_iterator __res = _Base::emplace(__position.base(),
452 std::forward<_Args>(__args)...);
7ffec97f
CJ
453 this->_M_invalidate_all();
454 return iterator(__res, this);
455 }
456#endif
526da49c
BI
457
458 iterator
7b61c5a9
PC
459#if __cplusplus >= 201103L
460 insert(const_iterator __position, const _Tp& __x)
461#else
285b36d6 462 insert(iterator __position, const _Tp& __x)
7b61c5a9 463#endif
285b36d6
BK
464 {
465 __glibcxx_check_insert(__position);
afe96d41 466 _Base_iterator __res = _Base::insert(__position.base(), __x);
285b36d6
BK
467 this->_M_invalidate_all();
468 return iterator(__res, this);
469 }
526da49c 470
734f5023 471#if __cplusplus >= 201103L
7ffec97f 472 iterator
7b61c5a9 473 insert(const_iterator __position, _Tp&& __x)
360b7bff 474 { return emplace(__position, std::move(__x)); }
988499f4 475
06eed9f5
PC
476 iterator
477 insert(const_iterator __position, initializer_list<value_type> __l)
988499f4 478 {
06eed9f5
PC
479 __glibcxx_check_insert(__position);
480 _Base_iterator __res = _Base::insert(__position.base(), __l);
988499f4 481 this->_M_invalidate_all();
06eed9f5 482 return iterator(__res, this);
988499f4 483 }
7ffec97f
CJ
484#endif
485
06eed9f5
PC
486#if __cplusplus >= 201103L
487 iterator
488 insert(const_iterator __position, size_type __n, const _Tp& __x)
489 {
490 __glibcxx_check_insert(__position);
491 _Base_iterator __res = _Base::insert(__position.base(), __n, __x);
492 this->_M_invalidate_all();
493 return iterator(__res, this);
494 }
495#else
526da49c 496 void
285b36d6
BK
497 insert(iterator __position, size_type __n, const _Tp& __x)
498 {
499 __glibcxx_check_insert(__position);
500 _Base::insert(__position.base(), __n, __x);
501 this->_M_invalidate_all();
502 }
06eed9f5 503#endif
526da49c 504
734f5023 505#if __cplusplus >= 201103L
2203cb90
PC
506 template<class _InputIterator,
507 typename = std::_RequireInputIter<_InputIterator>>
06eed9f5 508 iterator
15ee1a77 509 insert(const_iterator __position,
06eed9f5 510 _InputIterator __first, _InputIterator __last)
15ee1a77 511 {
24167c42
FD
512 typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
513 __glibcxx_check_insert_range(__position, __first, __last, __dist);
514 _Base_iterator __res;
515 if (__dist.second >= __gnu_debug::__dp_sign)
516 __res = _Base::insert(__position.base(),
517 __gnu_debug::__unsafe(__first),
518 __gnu_debug::__unsafe(__last));
519 else
520 __res = _Base::insert(__position.base(), __first, __last);
521
06eed9f5
PC
522 this->_M_invalidate_all();
523 return iterator(__res, this);
524 }
2203cb90 525#else
285b36d6 526 template<class _InputIterator>
15ee1a77
FD
527 void
528 insert(iterator __position,
285b36d6 529 _InputIterator __first, _InputIterator __last)
15ee1a77 530 {
24167c42
FD
531 typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
532 __glibcxx_check_insert_range(__position, __first, __last, __dist);
533
534 if (__dist.second >= __gnu_debug::__dp_sign)
535 _Base::insert(__position.base(),
536 __gnu_debug::__unsafe(__first),
537 __gnu_debug::__unsafe(__last));
538 else
539 _Base::insert(__position.base(), __first, __last);
540
285b36d6
BK
541 this->_M_invalidate_all();
542 }
06eed9f5 543#endif
526da49c
BI
544
545 void
d15ac9d9 546 pop_front() _GLIBCXX_NOEXCEPT
285b36d6
BK
547 {
548 __glibcxx_check_nonempty();
afe96d41 549 this->_M_invalidate_if(_Equal(_Base::begin()));
285b36d6
BK
550 _Base::pop_front();
551 }
526da49c
BI
552
553 void
d15ac9d9 554 pop_back() _GLIBCXX_NOEXCEPT
285b36d6
BK
555 {
556 __glibcxx_check_nonempty();
afe96d41 557 this->_M_invalidate_if(_Equal(--_Base::end()));
285b36d6
BK
558 _Base::pop_back();
559 }
526da49c
BI
560
561 iterator
94938aec
PC
562#if __cplusplus >= 201103L
563 erase(const_iterator __position)
564#else
565 erase(iterator __position)
566#endif
285b36d6
BK
567 {
568 __glibcxx_check_erase(__position);
94938aec
PC
569#if __cplusplus >= 201103L
570 _Base_const_iterator __victim = __position.base();
571#else
afe96d41 572 _Base_iterator __victim = __position.base();
94938aec
PC
573#endif
574 if (__victim == _Base::begin() || __victim == _Base::end() - 1)
285b36d6 575 {
afe96d41
FD
576 this->_M_invalidate_if(_Equal(__victim));
577 return iterator(_Base::erase(__victim), this);
285b36d6
BK
578 }
579 else
580 {
afe96d41 581 _Base_iterator __res = _Base::erase(__victim);
285b36d6
BK
582 this->_M_invalidate_all();
583 return iterator(__res, this);
584 }
585 }
526da49c
BI
586
587 iterator
94938aec
PC
588#if __cplusplus >= 201103L
589 erase(const_iterator __first, const_iterator __last)
590#else
285b36d6 591 erase(iterator __first, iterator __last)
94938aec 592#endif
285b36d6
BK
593 {
594 // _GLIBCXX_RESOLVE_LIB_DEFECTS
595 // 151. can't currently clear() empty container
596 __glibcxx_check_erase_range(__first, __last);
a7cee01d 597
cdfa3dbb 598 if (__first.base() == __last.base())
94938aec
PC
599#if __cplusplus >= 201103L
600 return iterator(__first.base()._M_const_cast(), this);
601#else
a7cee01d 602 return __first;
94938aec 603#endif
15ee1a77 604 else if (__first.base() == _Base::begin()
a7cee01d 605 || __last.base() == _Base::end())
285b36d6
BK
606 {
607 this->_M_detach_singular();
94938aec 608 for (_Base_const_iterator __position = __first.base();
afe96d41 609 __position != __last.base(); ++__position)
285b36d6 610 {
afe96d41 611 this->_M_invalidate_if(_Equal(__position));
285b36d6 612 }
bc2631e0 613 __try
526da49c 614 {
285b36d6 615 return iterator(_Base::erase(__first.base(), __last.base()),
526da49c 616 this);
285b36d6 617 }
bc2631e0 618 __catch(...)
285b36d6
BK
619 {
620 this->_M_revalidate_singular();
621 __throw_exception_again;
622 }
623 }
624 else
625 {
afe96d41
FD
626 _Base_iterator __res = _Base::erase(__first.base(),
627 __last.base());
285b36d6
BK
628 this->_M_invalidate_all();
629 return iterator(__res, this);
630 }
631 }
526da49c
BI
632
633 void
15ee1a77 634 swap(deque& __x)
c5d9ec56 635 _GLIBCXX_NOEXCEPT_IF( noexcept(declval<_Base&>().swap(__x)) )
285b36d6 636 {
15ee1a77 637 _Safe::_M_swap(__x);
285b36d6 638 _Base::swap(__x);
285b36d6 639 }
526da49c
BI
640
641 void
d3677132 642 clear() _GLIBCXX_NOEXCEPT
285b36d6
BK
643 {
644 _Base::clear();
645 this->_M_invalidate_all();
646 }
526da49c
BI
647
648 _Base&
15ee1a77 649 _M_base() _GLIBCXX_NOEXCEPT { return *this; }
285b36d6 650
526da49c 651 const _Base&
15ee1a77 652 _M_base() const _GLIBCXX_NOEXCEPT { return *this; }
285b36d6
BK
653 };
654
957f5fea
VV
655#if __cpp_deduction_guides >= 201606
656 template<typename _InputIterator, typename _ValT
657 = typename iterator_traits<_InputIterator>::value_type,
658 typename _Allocator = allocator<_ValT>,
659 typename = _RequireInputIter<_InputIterator>,
660 typename = _RequireAllocator<_Allocator>>
661 deque(_InputIterator, _InputIterator, _Allocator = _Allocator())
662 -> deque<_ValT, _Allocator>;
085c2f8f
JW
663
664 template<typename _Tp, typename _Allocator = allocator<_Tp>,
665 typename = _RequireAllocator<_Allocator>>
666 deque(size_t, _Tp, _Allocator = _Allocator())
667 -> deque<_Tp, _Allocator>;
957f5fea
VV
668#endif
669
285b36d6
BK
670 template<typename _Tp, typename _Alloc>
671 inline bool
526da49c 672 operator==(const deque<_Tp, _Alloc>& __lhs,
285b36d6
BK
673 const deque<_Tp, _Alloc>& __rhs)
674 { return __lhs._M_base() == __rhs._M_base(); }
675
bd2420f8
JW
676#if __cpp_lib_three_way_comparison
677 template<typename _Tp, typename _Alloc>
678 constexpr __detail::__synth3way_t<_Tp>
679 operator<=>(const deque<_Tp, _Alloc>& __x, const deque<_Tp, _Alloc>& __y)
680 { return __x._M_base() <=> __y._M_base(); }
681#else
285b36d6
BK
682 template<typename _Tp, typename _Alloc>
683 inline bool
526da49c 684 operator!=(const deque<_Tp, _Alloc>& __lhs,
285b36d6
BK
685 const deque<_Tp, _Alloc>& __rhs)
686 { return __lhs._M_base() != __rhs._M_base(); }
687
688 template<typename _Tp, typename _Alloc>
689 inline bool
ed540c0a
CJ
690 operator<(const deque<_Tp, _Alloc>& __lhs,
691 const deque<_Tp, _Alloc>& __rhs)
285b36d6
BK
692 { return __lhs._M_base() < __rhs._M_base(); }
693
694 template<typename _Tp, typename _Alloc>
695 inline bool
526da49c 696 operator<=(const deque<_Tp, _Alloc>& __lhs,
285b36d6
BK
697 const deque<_Tp, _Alloc>& __rhs)
698 { return __lhs._M_base() <= __rhs._M_base(); }
699
700 template<typename _Tp, typename _Alloc>
701 inline bool
526da49c 702 operator>=(const deque<_Tp, _Alloc>& __lhs,
285b36d6
BK
703 const deque<_Tp, _Alloc>& __rhs)
704 { return __lhs._M_base() >= __rhs._M_base(); }
705
706 template<typename _Tp, typename _Alloc>
707 inline bool
ed540c0a
CJ
708 operator>(const deque<_Tp, _Alloc>& __lhs,
709 const deque<_Tp, _Alloc>& __rhs)
285b36d6 710 { return __lhs._M_base() > __rhs._M_base(); }
bd2420f8 711#endif // three-way comparison
285b36d6
BK
712
713 template<typename _Tp, typename _Alloc>
714 inline void
715 swap(deque<_Tp, _Alloc>& __lhs, deque<_Tp, _Alloc>& __rhs)
c5d9ec56 716 _GLIBCXX_NOEXCEPT_IF(noexcept(__lhs.swap(__rhs)))
285b36d6 717 { __lhs.swap(__rhs); }
ed540c0a 718
45f388bb 719} // namespace __debug
3cbc7af0 720} // namespace std
285b36d6
BK
721
722#endif