1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_DEQUE
11#define _LIBCPP_DEQUE
12
13/*
14 deque synopsis
15
16namespace std
17{
18
19template <class T, class Allocator = allocator<T> >
20class deque
21{
22public:
23 // types:
24 typedef T value_type;
25 typedef Allocator allocator_type;
26
27 typedef typename allocator_type::reference reference;
28 typedef typename allocator_type::const_reference const_reference;
29 typedef implementation-defined iterator;
30 typedef implementation-defined const_iterator;
31 typedef typename allocator_type::size_type size_type;
32 typedef typename allocator_type::difference_type difference_type;
33
34 typedef typename allocator_type::pointer pointer;
35 typedef typename allocator_type::const_pointer const_pointer;
36 typedef std::reverse_iterator<iterator> reverse_iterator;
37 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
38
39 // construct/copy/destroy:
40 deque() noexcept(is_nothrow_default_constructible<allocator_type>::value);
41 explicit deque(const allocator_type& a);
42 explicit deque(size_type n);
43 explicit deque(size_type n, const allocator_type& a);
44 deque(size_type n, const value_type& v);
45 deque(size_type n, const value_type& v, const allocator_type& a);
46 template <class InputIterator>
47 deque(InputIterator f, InputIterator l);
48 template <class InputIterator>
49 deque(InputIterator f, InputIterator l, const allocator_type& a);
50 template<container-compatible-range<T> R>
51 deque(from_range_t, R&& rg, const Allocator& = Allocator()); // C++23
52 deque(const deque& c);
53 deque(deque&& c)
54 noexcept(is_nothrow_move_constructible<allocator_type>::value);
55 deque(initializer_list<value_type> il, const Allocator& a = allocator_type());
56 deque(const deque& c, const allocator_type& a);
57 deque(deque&& c, const allocator_type& a);
58 ~deque();
59
60 deque& operator=(const deque& c);
61 deque& operator=(deque&& c)
62 noexcept((allocator_traits<allocator_type>::propagate_on_container_move_assignment::value &&
63 is_nothrow_move_assignable<allocator_type>::value) ||
64 allocator_traits<allocator_type>::is_always_equal::value);
65 deque& operator=(initializer_list<value_type> il);
66
67 template <class InputIterator>
68 void assign(InputIterator f, InputIterator l);
69 template<container-compatible-range<T> R>
70 void assign_range(R&& rg); // C++23
71 void assign(size_type n, const value_type& v);
72 void assign(initializer_list<value_type> il);
73
74 allocator_type get_allocator() const noexcept;
75
76 // iterators:
77
78 iterator begin() noexcept;
79 const_iterator begin() const noexcept;
80 iterator end() noexcept;
81 const_iterator end() const noexcept;
82
83 reverse_iterator rbegin() noexcept;
84 const_reverse_iterator rbegin() const noexcept;
85 reverse_iterator rend() noexcept;
86 const_reverse_iterator rend() const noexcept;
87
88 const_iterator cbegin() const noexcept;
89 const_iterator cend() const noexcept;
90 const_reverse_iterator crbegin() const noexcept;
91 const_reverse_iterator crend() const noexcept;
92
93 // capacity:
94 size_type size() const noexcept;
95 size_type max_size() const noexcept;
96 void resize(size_type n);
97 void resize(size_type n, const value_type& v);
98 void shrink_to_fit();
99 bool empty() const noexcept;
100
101 // element access:
102 reference operator[](size_type i);
103 const_reference operator[](size_type i) const;
104 reference at(size_type i);
105 const_reference at(size_type i) const;
106 reference front();
107 const_reference front() const;
108 reference back();
109 const_reference back() const;
110
111 // modifiers:
112 void push_front(const value_type& v);
113 void push_front(value_type&& v);
114 template<container-compatible-range<T> R>
115 void prepend_range(R&& rg); // C++23
116 void push_back(const value_type& v);
117 void push_back(value_type&& v);
118 template<container-compatible-range<T> R>
119 void append_range(R&& rg); // C++23
120 template <class... Args> reference emplace_front(Args&&... args); // reference in C++17
121 template <class... Args> reference emplace_back(Args&&... args); // reference in C++17
122 template <class... Args> iterator emplace(const_iterator p, Args&&... args);
123 iterator insert(const_iterator p, const value_type& v);
124 iterator insert(const_iterator p, value_type&& v);
125 iterator insert(const_iterator p, size_type n, const value_type& v);
126 template <class InputIterator>
127 iterator insert(const_iterator p, InputIterator f, InputIterator l);
128 template<container-compatible-range<T> R>
129 iterator insert_range(const_iterator position, R&& rg); // C++23
130 iterator insert(const_iterator p, initializer_list<value_type> il);
131 void pop_front();
132 void pop_back();
133 iterator erase(const_iterator p);
134 iterator erase(const_iterator f, const_iterator l);
135 void swap(deque& c)
136 noexcept(allocator_traits<allocator_type>::is_always_equal::value); // C++17
137 void clear() noexcept;
138};
139
140template <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
141 deque(InputIterator, InputIterator, Allocator = Allocator())
142 -> deque<typename iterator_traits<InputIterator>::value_type, Allocator>; // C++17
143
144template<ranges::input_range R, class Allocator = allocator<ranges::range_value_t<R>>>
145 deque(from_range_t, R&&, Allocator = Allocator())
146 -> deque<ranges::range_value_t<R>, Allocator>; // C++23
147
148template <class T, class Allocator>
149 bool operator==(const deque<T,Allocator>& x, const deque<T,Allocator>& y);
150template <class T, class Allocator>
151 bool operator< (const deque<T,Allocator>& x, const deque<T,Allocator>& y); // removed in C++20
152template <class T, class Allocator>
153 bool operator!=(const deque<T,Allocator>& x, const deque<T,Allocator>& y); // removed in C++20
154template <class T, class Allocator>
155 bool operator> (const deque<T,Allocator>& x, const deque<T,Allocator>& y); // removed in C++20
156template <class T, class Allocator>
157 bool operator>=(const deque<T,Allocator>& x, const deque<T,Allocator>& y); // removed in C++20
158template <class T, class Allocator>
159 bool operator<=(const deque<T,Allocator>& x, const deque<T,Allocator>& y); // removed in C++20
160template<class T, class Allocator>
161 synth-three-way-result<T> operator<=>(const deque<T, Allocator>& x,
162 const deque<T, Allocator>& y); // since C++20
163
164// specialized algorithms:
165template <class T, class Allocator>
166 void swap(deque<T,Allocator>& x, deque<T,Allocator>& y)
167 noexcept(noexcept(x.swap(y)));
168
169template <class T, class Allocator, class U>
170 typename deque<T, Allocator>::size_type
171 erase(deque<T, Allocator>& c, const U& value); // C++20
172template <class T, class Allocator, class Predicate>
173 typename deque<T, Allocator>::size_type
174 erase_if(deque<T, Allocator>& c, Predicate pred); // C++20
175
176} // std
177
178*/
179
180#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
181# include <__cxx03/deque>
182#else
183# include <__algorithm/copy.h>
184# include <__algorithm/copy_backward.h>
185# include <__algorithm/copy_n.h>
186# include <__algorithm/equal.h>
187# include <__algorithm/fill_n.h>
188# include <__algorithm/lexicographical_compare.h>
189# include <__algorithm/lexicographical_compare_three_way.h>
190# include <__algorithm/max.h>
191# include <__algorithm/min.h>
192# include <__algorithm/move.h>
193# include <__algorithm/move_backward.h>
194# include <__algorithm/ranges_copy_n.h>
195# include <__algorithm/remove.h>
196# include <__algorithm/remove_if.h>
197# include <__assert>
198# include <__config>
199# include <__debug_utils/sanitizers.h>
200# include <__format/enable_insertable.h>
201# include <__fwd/deque.h>
202# include <__iterator/distance.h>
203# include <__iterator/iterator_traits.h>
204# include <__iterator/move_iterator.h>
205# include <__iterator/next.h>
206# include <__iterator/prev.h>
207# include <__iterator/reverse_iterator.h>
208# include <__iterator/segmented_iterator.h>
209# include <__memory/addressof.h>
210# include <__memory/allocator.h>
211# include <__memory/allocator_destructor.h>
212# include <__memory/allocator_traits.h>
213# include <__memory/compressed_pair.h>
214# include <__memory/pointer_traits.h>
215# include <__memory/swap_allocator.h>
216# include <__memory/temp_value.h>
217# include <__memory/unique_ptr.h>
218# include <__memory_resource/polymorphic_allocator.h>
219# include <__ranges/access.h>
220# include <__ranges/concepts.h>
221# include <__ranges/container_compatible_range.h>
222# include <__ranges/from_range.h>
223# include <__split_buffer>
224# include <__type_traits/conditional.h>
225# include <__type_traits/container_traits.h>
226# include <__type_traits/enable_if.h>
227# include <__type_traits/is_allocator.h>
228# include <__type_traits/is_convertible.h>
229# include <__type_traits/is_nothrow_assignable.h>
230# include <__type_traits/is_nothrow_constructible.h>
231# include <__type_traits/is_same.h>
232# include <__type_traits/is_swappable.h>
233# include <__type_traits/is_trivially_relocatable.h>
234# include <__type_traits/type_identity.h>
235# include <__utility/exception_guard.h>
236# include <__utility/forward.h>
237# include <__utility/move.h>
238# include <__utility/pair.h>
239# include <__utility/swap.h>
240# include <limits>
241# include <stdexcept>
242# include <version>
243
244// standard-mandated includes
245
246// [iterator.range]
247# include <__iterator/access.h>
248# include <__iterator/data.h>
249# include <__iterator/empty.h>
250# include <__iterator/reverse_access.h>
251# include <__iterator/size.h>
252
253// [deque.syn]
254# include <compare>
255# include <initializer_list>
256
257# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
258# pragma GCC system_header
259# endif
260
261_LIBCPP_PUSH_MACROS
262# include <__undef_macros>
263
264_LIBCPP_BEGIN_NAMESPACE_STD
265
266# ifndef _LIBCPP_ABI_USE_SMALL_DEQUE_BLOCK_SIZE
267template <class _ValueType, class _DiffType>
268struct __deque_block_size {
269 static const _DiffType value = sizeof(_ValueType) < 256 ? 4096 / sizeof(_ValueType) : 16;
270};
271# else
272template <class _ValueType, class _DiffType>
273struct __deque_block_size {
274 static const _DiffType value = sizeof(_ValueType) < 128 ? 512 / sizeof(_ValueType) : 4;
275};
276# endif
277
278template <class _ValueType,
279 class _Pointer,
280 class _Reference,
281 class _MapPointer,
282 class _DiffType,
283 _DiffType _BS =
284# ifdef _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE
285 // Keep template parameter to avoid changing all template declarations thoughout
286 // this file.
287 0
288# else
289 __deque_block_size<_ValueType, _DiffType>::value
290# endif
291 >
292class __deque_iterator {
293 using __map_iterator _LIBCPP_NODEBUG = __rebind_pointer_t<_Pointer, const __rebind_pointer_t<_Pointer, _ValueType> >;
294
295// TODO(LLVM 25): Remove this check
296# ifndef _LIBCPP_ABI_DEQUE_ITERATORS
297 static_assert(
298 sizeof(__map_iterator) == sizeof(_MapPointer) && _LIBCPP_ALIGNOF(__map_iterator) == _LIBCPP_ALIGNOF(_MapPointer),
299 "It looks like you are using fancy pointers such that FancyPtr<const FancyPtr<const value_type>> is not "
300 "layout-compatible with FancyPtr<FancyPtr<value_type>> or FancyPtr<const FancyPtr<value_type>>. "
301 "This means that your ABI is being broken between LLVM 22 and LLVM 23 if deque::iterator or "
302 "deque::const_iterator is used. If you don't care about your ABI being broken, define the "
303 "_LIBCPP_ABI_DEQUE_ITERATORS macro to silence this diagnostic.");
304# endif
305
306public:
307 typedef _Pointer pointer;
308 typedef _DiffType difference_type;
309
310private:
311 __map_iterator __m_iter_;
312 pointer __ptr_;
313
314 static const difference_type __block_size;
315
316public:
317 typedef _ValueType value_type;
318 typedef random_access_iterator_tag iterator_category;
319 typedef _Reference reference;
320
321 _LIBCPP_HIDE_FROM_ABI __deque_iterator() _NOEXCEPT
322# if _LIBCPP_STD_VER >= 14
323 : __m_iter_(nullptr),
324 __ptr_(nullptr)
325# endif
326 {
327 }
328
329 template <class _Pp, class _Rp, class _MP, __enable_if_t<is_convertible<_Pp, pointer>::value, int> = 0>
330 _LIBCPP_HIDE_FROM_ABI
331 __deque_iterator(const __deque_iterator<value_type, _Pp, _Rp, _MP, difference_type, _BS>& __it) _NOEXCEPT
332 : __m_iter_(__it.__m_iter_),
333 __ptr_(__it.__ptr_) {}
334
335 _LIBCPP_HIDE_FROM_ABI reference operator*() const { return *__ptr_; }
336 _LIBCPP_HIDE_FROM_ABI pointer operator->() const { return __ptr_; }
337
338 _LIBCPP_HIDE_FROM_ABI __deque_iterator& operator++() {
339 if (++__ptr_ - *__m_iter_ == __block_size) {
340 ++__m_iter_;
341 __ptr_ = *__m_iter_;
342 }
343 return *this;
344 }
345
346 _LIBCPP_HIDE_FROM_ABI __deque_iterator operator++(int) {
347 __deque_iterator __tmp = *this;
348 ++(*this);
349 return __tmp;
350 }
351
352 _LIBCPP_HIDE_FROM_ABI __deque_iterator& operator--() {
353 if (__ptr_ == *__m_iter_) {
354 --__m_iter_;
355 __ptr_ = *__m_iter_ + __block_size;
356 }
357 --__ptr_;
358 return *this;
359 }
360
361 _LIBCPP_HIDE_FROM_ABI __deque_iterator operator--(int) {
362 __deque_iterator __tmp = *this;
363 --(*this);
364 return __tmp;
365 }
366
367 _LIBCPP_HIDE_FROM_ABI __deque_iterator& operator+=(difference_type __n) {
368 if (__n != 0) {
369 __n += __ptr_ - *__m_iter_;
370 if (__n > 0) {
371 __m_iter_ += __n / __block_size;
372 __ptr_ = *__m_iter_ + __n % __block_size;
373 } else // (__n < 0)
374 {
375 difference_type __z = __block_size - 1 - __n;
376 __m_iter_ -= __z / __block_size;
377 __ptr_ = *__m_iter_ + (__block_size - 1 - __z % __block_size);
378 }
379 }
380 return *this;
381 }
382
383 _LIBCPP_HIDE_FROM_ABI __deque_iterator& operator-=(difference_type __n) { return *this += -__n; }
384
385 _LIBCPP_HIDE_FROM_ABI __deque_iterator operator+(difference_type __n) const {
386 __deque_iterator __t(*this);
387 __t += __n;
388 return __t;
389 }
390
391 _LIBCPP_HIDE_FROM_ABI __deque_iterator operator-(difference_type __n) const {
392 __deque_iterator __t(*this);
393 __t -= __n;
394 return __t;
395 }
396
397 _LIBCPP_HIDE_FROM_ABI friend __deque_iterator operator+(difference_type __n, const __deque_iterator& __it) {
398 return __it + __n;
399 }
400
401 _LIBCPP_HIDE_FROM_ABI friend difference_type operator-(const __deque_iterator& __x, const __deque_iterator& __y) {
402 if (__x != __y)
403 return (__x.__m_iter_ - __y.__m_iter_) * __block_size + (__x.__ptr_ - *__x.__m_iter_) -
404 (__y.__ptr_ - *__y.__m_iter_);
405 return 0;
406 }
407
408 _LIBCPP_HIDE_FROM_ABI reference operator[](difference_type __n) const { return *(*this + __n); }
409
410 _LIBCPP_HIDE_FROM_ABI friend bool operator==(const __deque_iterator& __x, const __deque_iterator& __y) {
411 return __x.__ptr_ == __y.__ptr_;
412 }
413
414# if _LIBCPP_STD_VER <= 17
415 _LIBCPP_HIDE_FROM_ABI friend bool operator!=(const __deque_iterator& __x, const __deque_iterator& __y) {
416 return !(__x == __y);
417 }
418 _LIBCPP_HIDE_FROM_ABI friend bool operator<(const __deque_iterator& __x, const __deque_iterator& __y) {
419 return __x.__m_iter_ < __y.__m_iter_ || (__x.__m_iter_ == __y.__m_iter_ && __x.__ptr_ < __y.__ptr_);
420 }
421
422 _LIBCPP_HIDE_FROM_ABI friend bool operator>(const __deque_iterator& __x, const __deque_iterator& __y) {
423 return __y < __x;
424 }
425
426 _LIBCPP_HIDE_FROM_ABI friend bool operator<=(const __deque_iterator& __x, const __deque_iterator& __y) {
427 return !(__y < __x);
428 }
429
430 _LIBCPP_HIDE_FROM_ABI friend bool operator>=(const __deque_iterator& __x, const __deque_iterator& __y) {
431 return !(__x < __y);
432 }
433
434# else
435
436 _LIBCPP_HIDE_FROM_ABI friend strong_ordering operator<=>(const __deque_iterator& __x, const __deque_iterator& __y) {
437 if (__x.__m_iter_ < __y.__m_iter_)
438 return strong_ordering::less;
439
440 if (__x.__m_iter_ == __y.__m_iter_) {
441 if constexpr (three_way_comparable<pointer, strong_ordering>) {
442 return __x.__ptr_ <=> __y.__ptr_;
443 } else {
444 if (__x.__ptr_ < __y.__ptr_)
445 return strong_ordering::less;
446
447 if (__x.__ptr_ == __y.__ptr_)
448 return strong_ordering::equal;
449
450 return strong_ordering::greater;
451 }
452 }
453
454 return strong_ordering::greater;
455 }
456# endif // _LIBCPP_STD_VER >= 20
457
458private:
459 _LIBCPP_HIDE_FROM_ABI explicit __deque_iterator(__map_iterator __m, pointer __p) _NOEXCEPT
460 : __m_iter_(__m),
461 __ptr_(__p) {}
462
463 template <class _Tp, class _Ap>
464 friend class deque;
465 template <class _Vp, class _Pp, class _Rp, class _MP, class _Dp, _Dp>
466 friend class __deque_iterator;
467
468 template <class>
469 friend struct __segmented_iterator_traits;
470};
471
472template <class _ValueType, class _Pointer, class _Reference, class _MapPointer, class _DiffType, _DiffType _BlockSize>
473struct __segmented_iterator_traits<
474 __deque_iterator<_ValueType, _Pointer, _Reference, _MapPointer, _DiffType, _BlockSize> > {
475private:
476 using _Iterator _LIBCPP_NODEBUG =
477 __deque_iterator<_ValueType, _Pointer, _Reference, _MapPointer, _DiffType, _BlockSize>;
478
479public:
480 using __segment_iterator _LIBCPP_NODEBUG = typename _Iterator::__map_iterator;
481 using __local_iterator _LIBCPP_NODEBUG = _Pointer;
482
483 static _LIBCPP_HIDE_FROM_ABI __segment_iterator __segment(_Iterator __iter) { return __iter.__m_iter_; }
484 static _LIBCPP_HIDE_FROM_ABI __local_iterator __local(_Iterator __iter) { return __iter.__ptr_; }
485 static _LIBCPP_HIDE_FROM_ABI __local_iterator __begin(__segment_iterator __iter) { return *__iter; }
486
487 static _LIBCPP_HIDE_FROM_ABI __local_iterator __end(__segment_iterator __iter) {
488 return *__iter + _Iterator::__block_size;
489 }
490
491 static _LIBCPP_HIDE_FROM_ABI _Iterator __compose(__segment_iterator __segment, __local_iterator __local) {
492 if (__segment && __local == __end(iter: __segment)) {
493 ++__segment;
494 return _Iterator(__segment, *__segment);
495 }
496 return _Iterator(__segment, __local);
497 }
498};
499
500template <class _ValueType, class _Pointer, class _Reference, class _MapPointer, class _DiffType, _DiffType _BlockSize>
501const _DiffType __deque_iterator<_ValueType, _Pointer, _Reference, _MapPointer, _DiffType, _BlockSize>::__block_size =
502 __deque_block_size<_ValueType, _DiffType>::value;
503
504template <class _Tp, class _Allocator /*= allocator<_Tp>*/>
505class deque {
506 template <class _Up, class _Alloc>
507 using __split_buffer _LIBCPP_NODEBUG = std::__split_buffer<_Up, _Alloc, __split_buffer_pointer_layout>;
508
509public:
510 // types:
511
512 using value_type = _Tp;
513
514 using allocator_type = _Allocator;
515 using __alloc_traits _LIBCPP_NODEBUG = allocator_traits<allocator_type>;
516 static_assert(__check_valid_allocator<allocator_type>::value, "");
517 static_assert(is_same<typename allocator_type::value_type, value_type>::value,
518 "Allocator::value_type must be same type as value_type");
519
520 using size_type = typename __alloc_traits::size_type;
521 using difference_type = typename __alloc_traits::difference_type;
522
523 using pointer = typename __alloc_traits::pointer;
524 using const_pointer = typename __alloc_traits::const_pointer;
525
526 using __pointer_allocator _LIBCPP_NODEBUG = __rebind_alloc<__alloc_traits, pointer>;
527 using __const_pointer_allocator _LIBCPP_NODEBUG = __rebind_alloc<__alloc_traits, const_pointer>;
528 using __map _LIBCPP_NODEBUG = __split_buffer<pointer, __pointer_allocator>;
529 using __map_alloc_traits _LIBCPP_NODEBUG = allocator_traits<__pointer_allocator>;
530 using __map_pointer _LIBCPP_NODEBUG = typename __map_alloc_traits::pointer;
531 using __map_const_pointer _LIBCPP_NODEBUG = typename allocator_traits<__const_pointer_allocator>::const_pointer;
532 using __map_const_iterator _LIBCPP_NODEBUG = typename __map::const_iterator;
533
534 using reference = value_type&;
535 using const_reference = const value_type&;
536
537 using iterator = __deque_iterator<value_type, pointer, reference, __map_pointer, difference_type>;
538 using const_iterator =
539 __deque_iterator<value_type, const_pointer, const_reference, __map_const_pointer, difference_type>;
540 using reverse_iterator = std::reverse_iterator<iterator>;
541 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
542
543 // A deque contains the following members which may be trivially relocatable:
544 // - __map: is a `__split_buffer`, see `__split_buffer` for more information on when it is trivially relocatable
545 // - size_type: is always trivially relocatable, since it is required to be an integral type
546 // - allocator_type: may not be trivially relocatable, so it's checked
547 // None of these are referencing the `deque` itself, so if all of them are trivially relocatable, `deque` is too.
548 using __trivially_relocatable _LIBCPP_NODEBUG = __conditional_t<
549 __libcpp_is_trivially_relocatable<__map>::value && __libcpp_is_trivially_relocatable<allocator_type>::value,
550 deque,
551 void>;
552
553 static_assert(is_nothrow_default_constructible<allocator_type>::value ==
554 is_nothrow_default_constructible<__pointer_allocator>::value,
555 "rebinding an allocator should not change exception guarantees");
556 static_assert(is_nothrow_move_constructible<allocator_type>::value ==
557 is_nothrow_move_constructible<typename __map::allocator_type>::value,
558 "rebinding an allocator should not change exception guarantees");
559
560private:
561 struct __deque_block_range {
562 explicit _LIBCPP_HIDE_FROM_ABI __deque_block_range(pointer __b, pointer __e) _NOEXCEPT
563 : __begin_(__b),
564 __end_(__e) {}
565 const pointer __begin_;
566 const pointer __end_;
567 };
568
569 struct __deque_range {
570 iterator __pos_;
571 const iterator __end_;
572
573 _LIBCPP_HIDE_FROM_ABI __deque_range(iterator __pos, iterator __e) _NOEXCEPT : __pos_(__pos), __end_(__e) {}
574
575 explicit _LIBCPP_HIDE_FROM_ABI operator bool() const _NOEXCEPT { return __pos_ != __end_; }
576
577 _LIBCPP_HIDE_FROM_ABI __deque_range begin() const { return *this; }
578
579 _LIBCPP_HIDE_FROM_ABI __deque_range end() const { return __deque_range(__end_, __end_); }
580 _LIBCPP_HIDE_FROM_ABI __deque_block_range operator*() const _NOEXCEPT {
581 if (__pos_.__m_iter_ == __end_.__m_iter_) {
582 return __deque_block_range(__pos_.__ptr_, __end_.__ptr_);
583 }
584 return __deque_block_range(__pos_.__ptr_, *__pos_.__m_iter_ + __block_size);
585 }
586
587 _LIBCPP_HIDE_FROM_ABI __deque_range& operator++() _NOEXCEPT {
588 if (__pos_.__m_iter_ == __end_.__m_iter_) {
589 __pos_ = __end_;
590 } else {
591 ++__pos_.__m_iter_;
592 __pos_.__ptr_ = *__pos_.__m_iter_;
593 }
594 return *this;
595 }
596
597 _LIBCPP_HIDE_FROM_ABI friend bool operator==(__deque_range const& __lhs, __deque_range const& __rhs) {
598 return __lhs.__pos_ == __rhs.__pos_;
599 }
600 _LIBCPP_HIDE_FROM_ABI friend bool operator!=(__deque_range const& __lhs, __deque_range const& __rhs) {
601 return !(__lhs == __rhs);
602 }
603 };
604
605 struct _ConstructTransaction {
606 _LIBCPP_HIDE_FROM_ABI _ConstructTransaction(deque* __db, __deque_block_range& __r)
607 : __pos_(__r.__begin_), __end_(__r.__end_), __begin_(__r.__begin_), __base_(__db) {}
608
609 _LIBCPP_HIDE_FROM_ABI ~_ConstructTransaction() { __base_->__size() += (__pos_ - __begin_); }
610
611 pointer __pos_;
612 const pointer __end_;
613
614 private:
615 const pointer __begin_;
616 deque* const __base_;
617 };
618
619 static const difference_type __block_size;
620
621 __map __map_;
622 size_type __start_;
623 _LIBCPP_COMPRESSED_PAIR(size_type, __size_, allocator_type, __alloc_);
624
625public:
626 // construct/copy/destroy:
627 _LIBCPP_HIDE_FROM_ABI deque() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
628 : __start_(0), __size_(0) {
629 __annotate_new(current_size: 0);
630 }
631
632 _LIBCPP_HIDE_FROM_ABI ~deque() {
633 clear();
634 __annotate_delete();
635 typename __map::iterator __i = __map_.begin();
636 typename __map::iterator __e = __map_.end();
637 for (; __i != __e; ++__i)
638 __alloc_traits::deallocate(__alloc(), *__i, __block_size);
639 }
640
641 _LIBCPP_HIDE_FROM_ABI explicit deque(const allocator_type& __a)
642 : __map_(__pointer_allocator(__a)), __start_(0), __size_(0), __alloc_(__a) {
643 __annotate_new(current_size: 0);
644 }
645
646 explicit _LIBCPP_HIDE_FROM_ABI deque(size_type __n);
647 explicit _LIBCPP_HIDE_FROM_ABI deque(size_type __n, const _Allocator& __a);
648 _LIBCPP_HIDE_FROM_ABI deque(size_type __n, const value_type& __v);
649
650 template <__enable_if_t<__is_allocator_v<_Allocator>, int> = 0>
651 _LIBCPP_HIDE_FROM_ABI deque(size_type __n, const value_type& __v, const allocator_type& __a)
652 : __map_(__pointer_allocator(__a)), __start_(0), __size_(0), __alloc_(__a) {
653 __annotate_new(current_size: 0);
654 if (__n > 0)
655 __append(__n, __v);
656 }
657
658 template <class _InputIter, __enable_if_t<__has_input_iterator_category<_InputIter>::value, int> = 0>
659 _LIBCPP_HIDE_FROM_ABI deque(_InputIter __f, _InputIter __l);
660 template <class _InputIter, __enable_if_t<__has_input_iterator_category<_InputIter>::value, int> = 0>
661 _LIBCPP_HIDE_FROM_ABI deque(_InputIter __f, _InputIter __l, const allocator_type& __a);
662
663# if _LIBCPP_STD_VER >= 23
664 template <_ContainerCompatibleRange<_Tp> _Range>
665 _LIBCPP_HIDE_FROM_ABI deque(from_range_t, _Range&& __range, const allocator_type& __a = allocator_type())
666 : __map_(__pointer_allocator(__a)), __start_(0), __size_(0), __alloc_(__a) {
667 if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) {
668 __append_with_size(ranges::begin(__range), ranges::distance(__range));
669
670 } else {
671 for (auto&& __e : __range) {
672 emplace_back(std::forward<decltype(__e)>(__e));
673 }
674 }
675 }
676# endif
677
678 _LIBCPP_HIDE_FROM_ABI deque(const deque& __c);
679 _LIBCPP_HIDE_FROM_ABI deque(const deque& __c, const __type_identity_t<allocator_type>& __a);
680
681 _LIBCPP_HIDE_FROM_ABI deque& operator=(const deque& __c);
682
683# ifndef _LIBCPP_CXX03_LANG
684 _LIBCPP_HIDE_FROM_ABI deque(initializer_list<value_type> __il);
685 _LIBCPP_HIDE_FROM_ABI deque(initializer_list<value_type> __il, const allocator_type& __a);
686
687 _LIBCPP_HIDE_FROM_ABI deque& operator=(initializer_list<value_type> __il) {
688 assign(__il);
689 return *this;
690 }
691
692 _LIBCPP_HIDE_FROM_ABI deque(deque&& __c) noexcept(is_nothrow_move_constructible<allocator_type>::value);
693 _LIBCPP_HIDE_FROM_ABI deque(deque&& __c, const __type_identity_t<allocator_type>& __a);
694 _LIBCPP_HIDE_FROM_ABI deque& operator=(deque&& __c) noexcept(
695 (__alloc_traits::propagate_on_container_move_assignment::value &&
696 is_nothrow_move_assignable<allocator_type>::value) ||
697 __alloc_traits::is_always_equal::value);
698
699 _LIBCPP_HIDE_FROM_ABI void assign(initializer_list<value_type> __il) { assign(__il.begin(), __il.end()); }
700# endif // _LIBCPP_CXX03_LANG
701
702 template <class _InputIter,
703 __enable_if_t<__has_input_iterator_category<_InputIter>::value &&
704 !__has_random_access_iterator_category<_InputIter>::value,
705 int> = 0>
706 _LIBCPP_HIDE_FROM_ABI void assign(_InputIter __f, _InputIter __l);
707 template <class _RAIter, __enable_if_t<__has_random_access_iterator_category<_RAIter>::value, int> = 0>
708 _LIBCPP_HIDE_FROM_ABI void assign(_RAIter __f, _RAIter __l);
709
710# if _LIBCPP_STD_VER >= 23
711 template <_ContainerCompatibleRange<_Tp> _Range>
712 _LIBCPP_HIDE_FROM_ABI void assign_range(_Range&& __range) {
713 if constexpr (ranges::random_access_range<_Range>) {
714 auto __n = static_cast<size_type>(ranges::distance(__range));
715 __assign_with_size_random_access(ranges::begin(__range), __n);
716
717 } else if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) {
718 auto __n = ranges::distance(__range);
719 auto __first = ranges::begin(__range);
720
721 auto __result = std::ranges::copy_n(std::move(__first), std::min<size_t>(__n, size()), begin());
722
723 if (static_cast<size_type>(__n) > size()) {
724 __append_with_size(std::move(__result.in), __n - size());
725 } else {
726 __erase_to_end(f: __result.out);
727 }
728
729 } else {
730 __assign_with_sentinel(ranges::begin(__range), ranges::end(__range));
731 }
732 }
733# endif
734
735 _LIBCPP_HIDE_FROM_ABI void assign(size_type __n, const value_type& __v);
736
737 _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const _NOEXCEPT;
738 _LIBCPP_HIDE_FROM_ABI allocator_type& __alloc() _NOEXCEPT { return __alloc_; }
739 _LIBCPP_HIDE_FROM_ABI const allocator_type& __alloc() const _NOEXCEPT { return __alloc_; }
740
741 // iterators:
742
743 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT {
744 auto __mp = __map_.begin() + __start_ / __block_size;
745 return iterator(__mp, __map_.empty() ? 0 : *__mp + __start_ % __block_size);
746 }
747
748 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT {
749 auto __mp = __map_.begin() + __start_ / __block_size;
750 return const_iterator(__mp, __map_.empty() ? 0 : *__mp + __start_ % __block_size);
751 }
752
753 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI iterator end() _NOEXCEPT {
754 size_type __p = size() + __start_;
755 auto __mp = __map_.begin() + __p / __block_size;
756 return iterator(__mp, __map_.empty() ? 0 : *__mp + __p % __block_size);
757 }
758
759 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT {
760 size_type __p = size() + __start_;
761 auto __mp = __map_.begin() + __p / __block_size;
762 return const_iterator(__mp, __map_.empty() ? 0 : *__mp + __p % __block_size);
763 }
764
765 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI reverse_iterator rbegin() _NOEXCEPT { return reverse_iterator(end()); }
766 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rbegin() const _NOEXCEPT {
767 return const_reverse_iterator(end());
768 }
769 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI reverse_iterator rend() _NOEXCEPT { return reverse_iterator(begin()); }
770 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rend() const _NOEXCEPT {
771 return const_reverse_iterator(begin());
772 }
773
774 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const _NOEXCEPT { return begin(); }
775 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI const_iterator cend() const _NOEXCEPT { return end(); }
776 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crbegin() const _NOEXCEPT {
777 return const_reverse_iterator(end());
778 }
779 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crend() const _NOEXCEPT {
780 return const_reverse_iterator(begin());
781 }
782
783 // capacity:
784 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __size(); }
785
786 _LIBCPP_HIDE_FROM_ABI size_type& __size() _NOEXCEPT { return __size_; }
787 _LIBCPP_HIDE_FROM_ABI const size_type& __size() const _NOEXCEPT { return __size_; }
788
789 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT {
790 return std::min<size_type>(__alloc_traits::max_size(__alloc()), numeric_limits<difference_type>::max());
791 }
792 _LIBCPP_HIDE_FROM_ABI void resize(size_type __n);
793 _LIBCPP_HIDE_FROM_ABI void resize(size_type __n, const value_type& __v);
794 _LIBCPP_HIDE_FROM_ABI void shrink_to_fit() _NOEXCEPT;
795 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return size() == 0; }
796
797 // element access:
798 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI reference operator[](size_type __i) _NOEXCEPT;
799 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI const_reference operator[](size_type __i) const _NOEXCEPT;
800 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI reference at(size_type __i);
801 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI const_reference at(size_type __i) const;
802 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI reference front() _NOEXCEPT;
803 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI const_reference front() const _NOEXCEPT;
804 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI reference back() _NOEXCEPT;
805 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI const_reference back() const _NOEXCEPT;
806
807 // 23.2.2.3 modifiers:
808 _LIBCPP_HIDE_FROM_ABI void push_front(const value_type& __v);
809 _LIBCPP_HIDE_FROM_ABI void push_back(const value_type& __v);
810
811 template <class... _Args>
812 _LIBCPP_HIDE_FROM_ABI iterator __emplace(const_iterator __p, _Args&&... __args);
813
814# ifndef _LIBCPP_CXX03_LANG
815# if _LIBCPP_STD_VER >= 17
816 template <class... _Args>
817 _LIBCPP_HIDE_FROM_ABI reference emplace_front(_Args&&... __args);
818 template <class... _Args>
819 _LIBCPP_HIDE_FROM_ABI reference emplace_back(_Args&&... __args);
820# else
821 template <class... _Args>
822 _LIBCPP_HIDE_FROM_ABI void emplace_front(_Args&&... __args);
823 template <class... _Args>
824 _LIBCPP_HIDE_FROM_ABI void emplace_back(_Args&&... __args);
825# endif
826
827 template <class... _Args>
828 _LIBCPP_HIDE_FROM_ABI iterator emplace(const_iterator __p, _Args&&... __args) {
829 return __emplace(__p, std::forward<_Args>(__args)...);
830 }
831
832 _LIBCPP_HIDE_FROM_ABI void push_front(value_type&& __v);
833 _LIBCPP_HIDE_FROM_ABI void push_back(value_type&& __v);
834
835# if _LIBCPP_STD_VER >= 23
836 template <_ContainerCompatibleRange<_Tp> _Range>
837 _LIBCPP_HIDE_FROM_ABI void prepend_range(_Range&& __range) {
838 insert_range(begin(), std::forward<_Range>(__range));
839 }
840
841 template <_ContainerCompatibleRange<_Tp> _Range>
842 _LIBCPP_HIDE_FROM_ABI void append_range(_Range&& __range) {
843 if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) {
844 __append_with_size(ranges::begin(__range), ranges::distance(__range));
845 } else {
846 __append_with_sentinel(ranges::begin(__range), ranges::end(__range));
847 }
848 }
849# endif
850
851 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, value_type&& __v) { return __emplace(__p, std::move(__v)); }
852
853 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, initializer_list<value_type> __il) {
854 return insert(__p, __il.begin(), __il.end());
855 }
856# endif // _LIBCPP_CXX03_LANG
857 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, const value_type& __v) { return __emplace(__p, __v); }
858 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, size_type __n, const value_type& __v);
859 template <class _InputIter, __enable_if_t<__has_exactly_input_iterator_category<_InputIter>::value, int> = 0>
860 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, _InputIter __f, _InputIter __l);
861 template <class _ForwardIterator,
862 __enable_if_t<__has_exactly_forward_iterator_category<_ForwardIterator>::value, int> = 0>
863 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, _ForwardIterator __f, _ForwardIterator __l);
864 template <class _BiIter, __enable_if_t<__has_bidirectional_iterator_category<_BiIter>::value, int> = 0>
865 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, _BiIter __f, _BiIter __l);
866
867# if _LIBCPP_STD_VER >= 23
868 template <_ContainerCompatibleRange<_Tp> _Range>
869 _LIBCPP_HIDE_FROM_ABI iterator insert_range(const_iterator __position, _Range&& __range) {
870 if constexpr (ranges::bidirectional_range<_Range>) {
871 auto __n = static_cast<size_type>(ranges::distance(__range));
872 return __insert_bidirectional(__position, ranges::begin(__range), ranges::end(__range), __n);
873
874 } else if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) {
875 auto __n = static_cast<size_type>(ranges::distance(__range));
876 return __insert_with_size(__position, ranges::begin(__range), __n);
877
878 } else {
879 return __insert_with_sentinel(__position, ranges::begin(__range), ranges::end(__range));
880 }
881 }
882# endif
883
884 _LIBCPP_HIDE_FROM_ABI void pop_front();
885 _LIBCPP_HIDE_FROM_ABI void pop_back();
886 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __p);
887 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __f, const_iterator __l);
888
889 _LIBCPP_HIDE_FROM_ABI void swap(deque& __c)
890# if _LIBCPP_STD_VER >= 14
891 _NOEXCEPT;
892# else
893 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable_v<allocator_type>);
894# endif
895 _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT;
896
897 _LIBCPP_HIDE_FROM_ABI bool __invariants() const {
898 if (!__map_.__invariants())
899 return false;
900 if (__map_.size() >= size_type(-1) / __block_size)
901 return false;
902 for (__map_const_iterator __i = __map_.begin(), __e = __map_.end(); __i != __e; ++__i)
903 if (*__i == nullptr)
904 return false;
905 if (__map_.size() != 0) {
906 if (size() >= __map_.size() * __block_size)
907 return false;
908 if (__start_ >= __map_.size() * __block_size - size())
909 return false;
910 } else {
911 if (size() != 0)
912 return false;
913 if (__start_ != 0)
914 return false;
915 }
916 return true;
917 }
918
919 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(deque& __c)
920 _NOEXCEPT_(!__alloc_traits::propagate_on_container_move_assignment::value ||
921 is_nothrow_move_assignable<allocator_type>::value) {
922 __move_assign_alloc(__c, integral_constant<bool, __alloc_traits::propagate_on_container_move_assignment::value>());
923 }
924
925 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(deque& __c, true_type)
926 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) {
927 __alloc() = std::move(__c.__alloc());
928 }
929
930 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(deque&, false_type) _NOEXCEPT {}
931
932 _LIBCPP_HIDE_FROM_ABI void __move_assign(deque& __c)
933 _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value&&
934 is_nothrow_move_assignable<allocator_type>::value) {
935 __map_ = std::move(__c.__map_);
936 __start_ = __c.__start_;
937 __size() = __c.size();
938 __move_assign_alloc(__c);
939 __c.__start_ = __c.__size() = 0;
940 }
941
942 _LIBCPP_HIDE_FROM_ABI static size_type __recommend_blocks(size_type __n) {
943 return __n / __block_size + (__n % __block_size != 0);
944 }
945 _LIBCPP_HIDE_FROM_ABI size_type __capacity() const {
946 return __map_.size() == 0 ? 0 : __map_.size() * __block_size - 1;
947 }
948 _LIBCPP_HIDE_FROM_ABI size_type __block_count() const { return __map_.size(); }
949
950 _LIBCPP_HIDE_FROM_ABI size_type __front_spare() const { return __start_; }
951 _LIBCPP_HIDE_FROM_ABI size_type __front_spare_blocks() const { return __front_spare() / __block_size; }
952 _LIBCPP_HIDE_FROM_ABI size_type __back_spare() const { return __capacity() - (__start_ + size()); }
953 _LIBCPP_HIDE_FROM_ABI size_type __back_spare_blocks() const { return __back_spare() / __block_size; }
954
955private:
956 enum __asan_annotation_type { __asan_unposion, __asan_poison };
957
958 enum __asan_annotation_place {
959 __asan_front_moved,
960 __asan_back_moved,
961 };
962
963 _LIBCPP_HIDE_FROM_ABI void __annotate_from_to(
964 size_type __beg,
965 size_type __end,
966 __asan_annotation_type __annotation_type,
967 __asan_annotation_place __place) const _NOEXCEPT {
968 (void)__beg;
969 (void)__end;
970 (void)__annotation_type;
971 (void)__place;
972# if _LIBCPP_ENABLE_ASAN_CONTAINER_CHECKS
973 // __beg - index of the first item to annotate
974 // __end - index behind the last item to annotate (so last item + 1)
975 // __annotation_type - __asan_unposion or __asan_poison
976 // __place - __asan_front_moved or __asan_back_moved
977 // Note: All indexes in __map_
978 if (__beg == __end)
979 return;
980 // __annotations_beg_map - first chunk which annotations we want to modify
981 // __annotations_end_map - last chunk which annotations we want to modify
982 // NOTE: if __end % __block_size == 0, __annotations_end_map points at the next block, which may not exist
983 __map_const_iterator __annotations_beg_map = __map_.begin() + __beg / __block_size;
984 __map_const_iterator __annotations_end_map = __map_.begin() + __end / __block_size;
985
986 bool const __poisoning = __annotation_type == __asan_poison;
987 // __old_c_beg_index - index of the first element in old container
988 // __old_c_end_index - index of the end of old container (last + 1)
989 // Note: may be outside the area we are annotating
990 size_t __old_c_beg_index = (__poisoning && __place == __asan_front_moved) ? __beg : __start_;
991 size_t __old_c_end_index = (__poisoning && __place == __asan_back_moved) ? __end : __start_ + size();
992 bool const __front = __place == __asan_front_moved;
993
994 if (__poisoning && empty()) {
995 // Special case: we shouldn't trust __start_
996 __old_c_beg_index = __beg;
997 __old_c_end_index = __end;
998 }
999 // __old_c_beg_map - memory block (chunk) with first element
1000 // __old_c_end_map - memory block (chunk) with end of old container
1001 // Note: if __old_c_end_index % __block_size == 0, __old_c_end_map points at the next block,
1002 // which may not exist
1003 __map_const_iterator __old_c_beg_map = __map_.begin() + __old_c_beg_index / __block_size;
1004 __map_const_iterator __old_c_end_map = __map_.begin() + __old_c_end_index / __block_size;
1005
1006 // One edge (front/end) of the container was moved and one was not modified.
1007 // __new_edge_index - index of new edge
1008 // __new_edge_map - memory block (chunk) with new edge, it always equals to
1009 // __annotations_beg_map or __annotations_end_map
1010 // __old_edge_map - memory block (chunk) with old edge, it always equals to
1011 // __old_c_beg_map or __old_c_end_map
1012 size_t __new_edge_index = (__poisoning ^ __front) ? __beg : __end;
1013 __map_const_iterator __new_edge_map = __map_.begin() + __new_edge_index / __block_size;
1014 __map_const_iterator __old_edge_map = __front ? __old_c_end_map : __old_c_beg_map;
1015
1016 // We iterate over map pointers (chunks) and fully poison all memory blocks between the first and the last.
1017 // First and last chunk may be partially poisoned.
1018 // __annotate_end_map may point at not existing chunk, therefore we have to have a check for it.
1019 for (__map_const_iterator __map_it = __annotations_beg_map; __map_it <= __annotations_end_map; ++__map_it) {
1020 if (__map_it == __annotations_end_map && __end % __block_size == 0)
1021 // Chunk may not exist, but nothing to do here anyway
1022 break;
1023
1024 // The beginning and the end of the current memory block
1025 const void* __mem_beg = std::__to_address(*__map_it);
1026 const void* __mem_end = std::__to_address(*__map_it + __block_size);
1027
1028 // The beginning of memory-in-use in the memory block before container modification
1029 const void* __old_beg =
1030 (__map_it == __old_c_beg_map) ? std::__to_address(*__map_it + (__old_c_beg_index % __block_size)) : __mem_beg;
1031
1032 // The end of memory-in-use in the memory block before container modification
1033 const void* __old_end;
1034 if (__map_it < __old_c_beg_map || __map_it > __old_c_end_map || (!__poisoning && empty()))
1035 __old_end = __old_beg;
1036 else
1037 __old_end = (__map_it == __old_c_end_map)
1038 ? std::__to_address(*__map_it + (__old_c_end_index % __block_size))
1039 : __mem_end;
1040
1041 // New edge of the container in current memory block
1042 // If the edge is in a different chunk it points on corresponding end of the memory block
1043 const void* __new_edge;
1044 if (__map_it == __new_edge_map)
1045 __new_edge = std::__to_address(*__map_it + (__new_edge_index % __block_size));
1046 else
1047 __new_edge = (__poisoning ^ __front) ? __mem_beg : __mem_end;
1048
1049 // Not modified edge of the container
1050 // If the edge is in a different chunk it points on corresponding end of the memory block
1051 const void* __old_edge;
1052 if (__map_it == __old_edge_map)
1053 __old_edge = __front ? __old_end : __old_beg;
1054 else
1055 __old_edge = __front ? __mem_end : __mem_beg;
1056
1057 // __new_beg - the beginning of memory-in-use in the memory block after container modification
1058 // __new_end - the end of memory-in-use in the memory block after container modification
1059 const void* __new_beg = __front ? __new_edge : __old_edge;
1060 const void* __new_end = __front ? __old_edge : __new_edge;
1061
1062 std::__annotate_double_ended_contiguous_container<_Allocator>(
1063 __mem_beg, __mem_end, __old_beg, __old_end, __new_beg, __new_end);
1064 }
1065# endif // _LIBCPP_ENABLE_ASAN_CONTAINER_CHECKS
1066 }
1067
1068 _LIBCPP_HIDE_FROM_ABI void __annotate_new(size_type __current_size) const _NOEXCEPT {
1069 (void)__current_size;
1070# if _LIBCPP_ENABLE_ASAN_CONTAINER_CHECKS
1071 if (__current_size == 0)
1072 __annotate_from_to(0, __map_.size() * __block_size, __asan_poison, __asan_back_moved);
1073 else {
1074 __annotate_from_to(0, __start_, __asan_poison, __asan_front_moved);
1075 __annotate_from_to(__start_ + __current_size, __map_.size() * __block_size, __asan_poison, __asan_back_moved);
1076 }
1077# endif // _LIBCPP_ENABLE_ASAN_CONTAINER_CHECKS
1078 }
1079
1080 _LIBCPP_HIDE_FROM_ABI void __annotate_delete() const _NOEXCEPT {
1081# if _LIBCPP_ENABLE_ASAN_CONTAINER_CHECKS
1082 if (empty()) {
1083 for (size_t __i = 0; __i < __map_.size(); ++__i) {
1084 __annotate_whole_block(__i, __asan_unposion);
1085 }
1086 } else {
1087 __annotate_from_to(0, __start_, __asan_unposion, __asan_front_moved);
1088 __annotate_from_to(__start_ + size(), __map_.size() * __block_size, __asan_unposion, __asan_back_moved);
1089 }
1090# endif // _LIBCPP_ENABLE_ASAN_CONTAINER_CHECKS
1091 }
1092
1093 _LIBCPP_HIDE_FROM_ABI void __annotate_increase_front(size_type __n) const _NOEXCEPT {
1094 (void)__n;
1095# if _LIBCPP_ENABLE_ASAN_CONTAINER_CHECKS
1096 __annotate_from_to(__start_ - __n, __start_, __asan_unposion, __asan_front_moved);
1097# endif
1098 }
1099
1100 _LIBCPP_HIDE_FROM_ABI void __annotate_increase_back(size_type __n) const _NOEXCEPT {
1101 (void)__n;
1102# if _LIBCPP_ENABLE_ASAN_CONTAINER_CHECKS
1103 __annotate_from_to(__start_ + size(), __start_ + size() + __n, __asan_unposion, __asan_back_moved);
1104# endif
1105 }
1106
1107 _LIBCPP_HIDE_FROM_ABI void __annotate_shrink_front(size_type __old_size, size_type __old_start) const _NOEXCEPT {
1108 (void)__old_size;
1109 (void)__old_start;
1110# if _LIBCPP_ENABLE_ASAN_CONTAINER_CHECKS
1111 __annotate_from_to(__old_start, __old_start + (__old_size - size()), __asan_poison, __asan_front_moved);
1112# endif
1113 }
1114
1115 _LIBCPP_HIDE_FROM_ABI void __annotate_shrink_back(size_type __old_size, size_type __old_start) const _NOEXCEPT {
1116 (void)__old_size;
1117 (void)__old_start;
1118# if _LIBCPP_ENABLE_ASAN_CONTAINER_CHECKS
1119 __annotate_from_to(__old_start + size(), __old_start + __old_size, __asan_poison, __asan_back_moved);
1120# endif
1121 }
1122
1123 _LIBCPP_HIDE_FROM_ABI void __annotate_poison_block(const void* __beginning, const void* __end) const _NOEXCEPT {
1124 std::__annotate_double_ended_contiguous_container<_Allocator>(__beginning, __end, __beginning, __end, __end, __end);
1125 }
1126
1127 _LIBCPP_HIDE_FROM_ABI void
1128 __annotate_whole_block(size_t __block_index, __asan_annotation_type __annotation_type) const _NOEXCEPT {
1129 (void)__block_index;
1130 (void)__annotation_type;
1131# if _LIBCPP_ENABLE_ASAN_CONTAINER_CHECKS
1132 __map_const_iterator __block_it = __map_.begin() + __block_index;
1133 const void* __block_start = std::__to_address(*__block_it);
1134 const void* __block_end = std::__to_address(*__block_it + __block_size);
1135
1136 if (__annotation_type == __asan_poison)
1137 __annotate_poison_block(__block_start, __block_end);
1138 else {
1139 std::__annotate_double_ended_contiguous_container<_Allocator>(
1140 __block_start, __block_end, __block_start, __block_start, __block_start, __block_end);
1141 }
1142# endif
1143 }
1144# if _LIBCPP_ENABLE_ASAN_CONTAINER_CHECKS
1145
1146public:
1147 _LIBCPP_HIDE_FROM_ABI bool __verify_asan_annotations() const _NOEXCEPT {
1148 // This function tests deque object annotations.
1149 if (empty()) {
1150 for (__map_const_iterator __it = __map_.begin(); __it != __map_.end(); ++__it) {
1151 if (!::__sanitizer_verify_double_ended_contiguous_container(
1152 std::__to_address(*__it),
1153 std::__to_address(*__it),
1154 std::__to_address(*__it),
1155 std::__to_address(*__it + __block_size)))
1156 return false;
1157 }
1158
1159 return true;
1160 }
1161
1162 size_type __end = __start_ + size();
1163 __map_const_iterator __first_mp = __map_.begin() + __start_ / __block_size;
1164 __map_const_iterator __last_mp = __map_.begin() + (__end - 1) / __block_size;
1165
1166 // Pointers to first and after last elements
1167 // Those can be in different deque blocks
1168 const void* __p_beg = std::__to_address(*__first_mp + (__start_ % __block_size));
1169 const void* __p_end =
1170 std::__to_address(*__last_mp + ((__end % __block_size == 0) ? __block_size : __end % __block_size));
1171
1172 for (__map_const_iterator __it = __map_.begin(); __it != __map_.end(); ++__it) {
1173 // Go over all blocks, find the place we are in and verify its annotations
1174 // Note that __p_end points *behind* the last item.
1175
1176 // - blocks before the first block with container elements
1177 // - first block with items
1178 // - last block with items
1179 // - blocks after last block with ciontainer elements
1180
1181 // Is the block before or after deque blocks that contain elements?
1182 if (__it < __first_mp || __it > __last_mp) {
1183 if (!::__sanitizer_verify_double_ended_contiguous_container(
1184 std::__to_address(*__it),
1185 std::__to_address(*__it),
1186 std::__to_address(*__it),
1187 std::__to_address(*__it + __block_size)))
1188 return false;
1189 } else {
1190 const void* __containers_buffer_beg = (__it == __first_mp) ? __p_beg : (const void*)std::__to_address(*__it);
1191 const void* __containers_buffer_end =
1192 (__it == __last_mp) ? __p_end : (const void*)std::__to_address(*__it + __block_size);
1193 if (!::__sanitizer_verify_double_ended_contiguous_container(
1194 std::__to_address(*__it),
1195 __containers_buffer_beg,
1196 __containers_buffer_end,
1197 std::__to_address(*__it + __block_size))) {
1198 return false;
1199 }
1200 }
1201 }
1202 return true;
1203 }
1204
1205private:
1206# endif // _LIBCPP_ENABLE_ASAN_CONTAINER_CHECKS
1207 _LIBCPP_HIDE_FROM_ABI bool __maybe_remove_front_spare(bool __keep_one = true) {
1208 if (__front_spare_blocks() >= 2 || (!__keep_one && __front_spare_blocks())) {
1209 __annotate_whole_block(block_index: 0, annotation_type: __asan_unposion);
1210 __alloc_traits::deallocate(__alloc(), __map_.front(), __block_size);
1211 __map_.pop_front();
1212 __start_ -= __block_size;
1213 return true;
1214 }
1215 return false;
1216 }
1217
1218 _LIBCPP_HIDE_FROM_ABI bool __maybe_remove_back_spare(bool __keep_one = true) {
1219 if (__back_spare_blocks() >= 2 || (!__keep_one && __back_spare_blocks())) {
1220 __annotate_whole_block(block_index: __map_.size() - 1, annotation_type: __asan_unposion);
1221 __alloc_traits::deallocate(__alloc(), __map_.back(), __block_size);
1222 __map_.pop_back();
1223 return true;
1224 }
1225 return false;
1226 }
1227
1228 template <class _Iterator, class _Sentinel>
1229 _LIBCPP_HIDE_FROM_ABI void __assign_with_sentinel(_Iterator __f, _Sentinel __l);
1230
1231 template <class _RandomAccessIterator>
1232 _LIBCPP_HIDE_FROM_ABI void __assign_with_size_random_access(_RandomAccessIterator __f, difference_type __n);
1233 template <class _AlgPolicy, class _Iterator>
1234 _LIBCPP_HIDE_FROM_ABI void __assign_with_size(_Iterator __f, difference_type __n);
1235
1236 template <class _Iterator, class _Sentinel>
1237 _LIBCPP_HIDE_FROM_ABI iterator __insert_with_sentinel(const_iterator __p, _Iterator __f, _Sentinel __l);
1238
1239 template <class _Iterator>
1240 _LIBCPP_HIDE_FROM_ABI iterator __insert_with_size(const_iterator __p, _Iterator __f, size_type __n);
1241
1242 template <class _BiIter, class _Sentinel>
1243 _LIBCPP_HIDE_FROM_ABI iterator
1244 __insert_bidirectional(const_iterator __p, _BiIter __f, _Sentinel __sent, size_type __n);
1245 template <class _BiIter>
1246 _LIBCPP_HIDE_FROM_ABI iterator __insert_bidirectional(const_iterator __p, _BiIter __f, _BiIter __l, size_type __n);
1247
1248 template <class _InpIter, __enable_if_t<__has_exactly_input_iterator_category<_InpIter>::value, int> = 0>
1249 _LIBCPP_HIDE_FROM_ABI void __append(_InpIter __f, _InpIter __l);
1250 template <class _ForIter, __enable_if_t<__has_forward_iterator_category<_ForIter>::value, int> = 0>
1251 _LIBCPP_HIDE_FROM_ABI void __append(_ForIter __f, _ForIter __l);
1252
1253 template <class _InputIterator>
1254 _LIBCPP_HIDE_FROM_ABI void __append_with_size(_InputIterator __from, size_type __n);
1255 template <class _InputIterator, class _Sentinel>
1256 _LIBCPP_HIDE_FROM_ABI void __append_with_sentinel(_InputIterator __f, _Sentinel __l);
1257
1258 _LIBCPP_HIDE_FROM_ABI void __append(size_type __n);
1259 _LIBCPP_HIDE_FROM_ABI void __append(size_type __n, const value_type& __v);
1260 _LIBCPP_HIDE_FROM_ABI void __erase_to_end(const_iterator __f);
1261 _LIBCPP_HIDE_FROM_ABI void __add_front_capacity();
1262 _LIBCPP_HIDE_FROM_ABI void __add_front_capacity(size_type __n);
1263 _LIBCPP_HIDE_FROM_ABI void __add_back_capacity();
1264 _LIBCPP_HIDE_FROM_ABI void __add_back_capacity(size_type __n);
1265 _LIBCPP_HIDE_FROM_ABI iterator __move_and_check(iterator __f, iterator __l, iterator __r, const_pointer& __vt);
1266 _LIBCPP_HIDE_FROM_ABI iterator
1267 __move_backward_and_check(iterator __f, iterator __l, iterator __r, const_pointer& __vt);
1268 _LIBCPP_HIDE_FROM_ABI void __move_construct_and_check(iterator __f, iterator __l, iterator __r, const_pointer& __vt);
1269 _LIBCPP_HIDE_FROM_ABI void
1270 __move_construct_backward_and_check(iterator __f, iterator __l, iterator __r, const_pointer& __vt);
1271
1272 _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const deque& __c) {
1273 __copy_assign_alloc(__c, integral_constant<bool, __alloc_traits::propagate_on_container_copy_assignment::value>());
1274 }
1275
1276 _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const deque& __c, true_type) {
1277 if (__alloc() != __c.__alloc()) {
1278 clear();
1279 shrink_to_fit();
1280 }
1281 __alloc() = __c.__alloc();
1282 __map_.__get_allocator() = __c.__map_.__get_allocator();
1283 }
1284
1285 _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const deque&, false_type) {}
1286
1287 _LIBCPP_HIDE_FROM_ABI void __move_assign(deque& __c, true_type)
1288 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
1289 _LIBCPP_HIDE_FROM_ABI void __move_assign(deque& __c, false_type);
1290};
1291
1292template <class _Tp, class _Alloc>
1293_LIBCPP_CONSTEXPR const typename allocator_traits<_Alloc>::difference_type deque<_Tp, _Alloc>::__block_size =
1294 __deque_block_size<value_type, difference_type>::value;
1295
1296# if _LIBCPP_STD_VER >= 17
1297template <class _InputIterator,
1298 class _Alloc = allocator<__iterator_value_type<_InputIterator>>,
1299 class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
1300 class = enable_if_t<__is_allocator_v<_Alloc>>>
1301deque(_InputIterator, _InputIterator) -> deque<__iterator_value_type<_InputIterator>, _Alloc>;
1302
1303template <class _InputIterator,
1304 class _Alloc,
1305 class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
1306 class = enable_if_t<__is_allocator_v<_Alloc>>>
1307deque(_InputIterator, _InputIterator, _Alloc) -> deque<__iterator_value_type<_InputIterator>, _Alloc>;
1308# endif
1309
1310# if _LIBCPP_STD_VER >= 23
1311template <ranges::input_range _Range,
1312 class _Alloc = allocator<ranges::range_value_t<_Range>>,
1313 class = enable_if_t<__is_allocator_v<_Alloc>>>
1314deque(from_range_t, _Range&&, _Alloc = _Alloc()) -> deque<ranges::range_value_t<_Range>, _Alloc>;
1315# endif
1316
1317template <class _Tp, class _Allocator>
1318deque<_Tp, _Allocator>::deque(size_type __n) : __start_(0), __size_(0) {
1319 __annotate_new(current_size: 0);
1320 if (__n > 0)
1321 __append(__n);
1322}
1323
1324template <class _Tp, class _Allocator>
1325deque<_Tp, _Allocator>::deque(size_type __n, const _Allocator& __a)
1326 : __map_(__pointer_allocator(__a)), __start_(0), __size_(0), __alloc_(__a) {
1327 __annotate_new(current_size: 0);
1328 if (__n > 0)
1329 __append(__n);
1330}
1331
1332template <class _Tp, class _Allocator>
1333deque<_Tp, _Allocator>::deque(size_type __n, const value_type& __v) : __start_(0), __size_(0) {
1334 __annotate_new(current_size: 0);
1335 if (__n > 0)
1336 __append(__n, __v);
1337}
1338
1339template <class _Tp, class _Allocator>
1340template <class _InputIter, __enable_if_t<__has_input_iterator_category<_InputIter>::value, int> >
1341deque<_Tp, _Allocator>::deque(_InputIter __f, _InputIter __l) : __start_(0), __size_(0) {
1342 __annotate_new(current_size: 0);
1343 __append(__f, __l);
1344}
1345
1346template <class _Tp, class _Allocator>
1347template <class _InputIter, __enable_if_t<__has_input_iterator_category<_InputIter>::value, int> >
1348deque<_Tp, _Allocator>::deque(_InputIter __f, _InputIter __l, const allocator_type& __a)
1349 : __map_(__pointer_allocator(__a)), __start_(0), __size_(0), __alloc_(__a) {
1350 __annotate_new(current_size: 0);
1351 __append(__f, __l);
1352}
1353
1354template <class _Tp, class _Allocator>
1355deque<_Tp, _Allocator>::deque(const deque& __c)
1356 : __map_(__pointer_allocator(__alloc_traits::select_on_container_copy_construction(__c.__alloc()))),
1357 __start_(0),
1358 __size_(0),
1359 __alloc_(__map_.__get_allocator()) {
1360 __annotate_new(current_size: 0);
1361 __append(__c.begin(), __c.end());
1362}
1363
1364template <class _Tp, class _Allocator>
1365deque<_Tp, _Allocator>::deque(const deque& __c, const __type_identity_t<allocator_type>& __a)
1366 : __map_(__pointer_allocator(__a)), __start_(0), __size_(0), __alloc_(__a) {
1367 __annotate_new(current_size: 0);
1368 __append(__c.begin(), __c.end());
1369}
1370
1371template <class _Tp, class _Allocator>
1372deque<_Tp, _Allocator>& deque<_Tp, _Allocator>::operator=(const deque& __c) {
1373 if (this != std::addressof(__c)) {
1374 __copy_assign_alloc(__c);
1375 assign(__c.begin(), __c.end());
1376 }
1377 return *this;
1378}
1379
1380# ifndef _LIBCPP_CXX03_LANG
1381
1382template <class _Tp, class _Allocator>
1383deque<_Tp, _Allocator>::deque(initializer_list<value_type> __il) : __start_(0), __size_(0) {
1384 __annotate_new(current_size: 0);
1385 __append(__il.begin(), __il.end());
1386}
1387
1388template <class _Tp, class _Allocator>
1389deque<_Tp, _Allocator>::deque(initializer_list<value_type> __il, const allocator_type& __a)
1390 : __map_(__pointer_allocator(__a)), __start_(0), __size_(0), __alloc_(__a) {
1391 __annotate_new(current_size: 0);
1392 __append(__il.begin(), __il.end());
1393}
1394
1395template <class _Tp, class _Allocator>
1396inline deque<_Tp, _Allocator>::deque(deque&& __c) noexcept(is_nothrow_move_constructible<allocator_type>::value)
1397 : __map_(std::move(__c.__map_)),
1398 __start_(std::move(__c.__start_)),
1399 __size_(std::move(__c.__size_)),
1400 __alloc_(std::move(__c.__alloc_)) {
1401 __c.__start_ = 0;
1402 __c.__size() = 0;
1403}
1404
1405template <class _Tp, class _Allocator>
1406inline deque<_Tp, _Allocator>::deque(deque&& __c, const __type_identity_t<allocator_type>& __a)
1407 : __map_(std::move(__c.__map_), __pointer_allocator(__a)),
1408 __start_(std::move(__c.__start_)),
1409 __size_(std::move(__c.__size_)),
1410 __alloc_(__a) {
1411 if (__a == __c.__alloc()) {
1412 __c.__start_ = 0;
1413 __c.__size() = 0;
1414 } else {
1415 __map_.clear();
1416 __start_ = 0;
1417 __size() = 0;
1418 typedef move_iterator<iterator> _Ip;
1419 assign(_Ip(__c.begin()), _Ip(__c.end()));
1420 }
1421}
1422
1423template <class _Tp, class _Allocator>
1424inline deque<_Tp, _Allocator>& deque<_Tp, _Allocator>::operator=(deque&& __c) noexcept(
1425 (__alloc_traits::propagate_on_container_move_assignment::value &&
1426 is_nothrow_move_assignable<allocator_type>::value) ||
1427 __alloc_traits::is_always_equal::value) {
1428 __move_assign(__c, integral_constant<bool, __alloc_traits::propagate_on_container_move_assignment::value>());
1429 return *this;
1430}
1431
1432template <class _Tp, class _Allocator>
1433void deque<_Tp, _Allocator>::__move_assign(deque& __c, false_type) {
1434 if (__alloc() != __c.__alloc()) {
1435 typedef move_iterator<iterator> _Ip;
1436 assign(_Ip(__c.begin()), _Ip(__c.end()));
1437 } else
1438 __move_assign(__c, true_type());
1439}
1440
1441template <class _Tp, class _Allocator>
1442void deque<_Tp, _Allocator>::__move_assign(deque& __c,
1443 true_type) noexcept(is_nothrow_move_assignable<allocator_type>::value) {
1444 clear();
1445 shrink_to_fit();
1446 __move_assign(__c);
1447}
1448
1449# endif // _LIBCPP_CXX03_LANG
1450
1451template <class _Tp, class _Allocator>
1452template <class _InputIter,
1453 __enable_if_t<__has_input_iterator_category<_InputIter>::value &&
1454 !__has_random_access_iterator_category<_InputIter>::value,
1455 int> >
1456void deque<_Tp, _Allocator>::assign(_InputIter __f, _InputIter __l) {
1457 __assign_with_sentinel(__f, __l);
1458}
1459
1460template <class _Tp, class _Allocator>
1461template <class _Iterator, class _Sentinel>
1462_LIBCPP_HIDE_FROM_ABI void deque<_Tp, _Allocator>::__assign_with_sentinel(_Iterator __f, _Sentinel __l) {
1463 iterator __i = begin();
1464 iterator __e = end();
1465 for (; __f != __l && __i != __e; ++__f, (void)++__i)
1466 *__i = *__f;
1467 if (__f != __l)
1468 __append_with_sentinel(std::move(__f), std::move(__l));
1469 else
1470 __erase_to_end(f: __i);
1471}
1472
1473template <class _Tp, class _Allocator>
1474template <class _RAIter, __enable_if_t<__has_random_access_iterator_category<_RAIter>::value, int> >
1475void deque<_Tp, _Allocator>::assign(_RAIter __f, _RAIter __l) {
1476 __assign_with_size_random_access(__f, __l - __f);
1477}
1478
1479template <class _Tp, class _Allocator>
1480template <class _RandomAccessIterator>
1481_LIBCPP_HIDE_FROM_ABI void
1482deque<_Tp, _Allocator>::__assign_with_size_random_access(_RandomAccessIterator __f, difference_type __n) {
1483 if (static_cast<size_type>(__n) > size()) {
1484 auto __l = __f + size();
1485 std::copy(__f, __l, begin());
1486 __append_with_size(__l, __n - size());
1487 } else
1488 __erase_to_end(f: std::copy_n(__f, __n, begin()));
1489}
1490
1491template <class _Tp, class _Allocator>
1492void deque<_Tp, _Allocator>::assign(size_type __n, const value_type& __v) {
1493 if (__n > size()) {
1494 std::fill_n(begin(), size(), __v);
1495 __n -= size();
1496 __append(__n, __v);
1497 } else
1498 __erase_to_end(f: std::fill_n(begin(), __n, __v));
1499}
1500
1501template <class _Tp, class _Allocator>
1502inline _Allocator deque<_Tp, _Allocator>::get_allocator() const _NOEXCEPT {
1503 return __alloc();
1504}
1505
1506template <class _Tp, class _Allocator>
1507void deque<_Tp, _Allocator>::resize(size_type __n) {
1508 if (__n > size())
1509 __append(__n - size());
1510 else if (__n < size())
1511 __erase_to_end(f: begin() + __n);
1512}
1513
1514template <class _Tp, class _Allocator>
1515void deque<_Tp, _Allocator>::resize(size_type __n, const value_type& __v) {
1516 if (__n > size())
1517 __append(__n - size(), __v);
1518 else if (__n < size())
1519 __erase_to_end(f: begin() + __n);
1520}
1521
1522template <class _Tp, class _Allocator>
1523void deque<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT {
1524 allocator_type& __a = __alloc();
1525 if (empty()) {
1526 __annotate_delete();
1527 while (__map_.size() > 0) {
1528 __alloc_traits::deallocate(__a, __map_.back(), __block_size);
1529 __map_.pop_back();
1530 }
1531 __start_ = 0;
1532 } else {
1533 __maybe_remove_front_spare(/*__keep_one=*/keep_one: false);
1534 __maybe_remove_back_spare(/*__keep_one=*/keep_one: false);
1535 }
1536 __map_.shrink_to_fit();
1537}
1538
1539template <class _Tp, class _Allocator>
1540inline typename deque<_Tp, _Allocator>::reference deque<_Tp, _Allocator>::operator[](size_type __i) _NOEXCEPT {
1541 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__i < size(), "deque::operator[] index out of bounds");
1542 size_type __p = __start_ + __i;
1543 return *(*(__map_.begin() + __p / __block_size) + __p % __block_size);
1544}
1545
1546template <class _Tp, class _Allocator>
1547inline typename deque<_Tp, _Allocator>::const_reference
1548deque<_Tp, _Allocator>::operator[](size_type __i) const _NOEXCEPT {
1549 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__i < size(), "deque::operator[] index out of bounds");
1550 size_type __p = __start_ + __i;
1551 return *(*(__map_.begin() + __p / __block_size) + __p % __block_size);
1552}
1553
1554template <class _Tp, class _Allocator>
1555inline typename deque<_Tp, _Allocator>::reference deque<_Tp, _Allocator>::at(size_type __i) {
1556 if (__i >= size())
1557 std::__throw_out_of_range(msg: "deque");
1558 size_type __p = __start_ + __i;
1559 return *(*(__map_.begin() + __p / __block_size) + __p % __block_size);
1560}
1561
1562template <class _Tp, class _Allocator>
1563inline typename deque<_Tp, _Allocator>::const_reference deque<_Tp, _Allocator>::at(size_type __i) const {
1564 if (__i >= size())
1565 std::__throw_out_of_range(msg: "deque");
1566 size_type __p = __start_ + __i;
1567 return *(*(__map_.begin() + __p / __block_size) + __p % __block_size);
1568}
1569
1570template <class _Tp, class _Allocator>
1571inline typename deque<_Tp, _Allocator>::reference deque<_Tp, _Allocator>::front() _NOEXCEPT {
1572 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "deque::front called on an empty deque");
1573 return *(*(__map_.begin() + __start_ / __block_size) + __start_ % __block_size);
1574}
1575
1576template <class _Tp, class _Allocator>
1577inline typename deque<_Tp, _Allocator>::const_reference deque<_Tp, _Allocator>::front() const _NOEXCEPT {
1578 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "deque::front called on an empty deque");
1579 return *(*(__map_.begin() + __start_ / __block_size) + __start_ % __block_size);
1580}
1581
1582template <class _Tp, class _Allocator>
1583inline typename deque<_Tp, _Allocator>::reference deque<_Tp, _Allocator>::back() _NOEXCEPT {
1584 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "deque::back called on an empty deque");
1585 size_type __p = size() + __start_ - 1;
1586 return *(*(__map_.begin() + __p / __block_size) + __p % __block_size);
1587}
1588
1589template <class _Tp, class _Allocator>
1590inline typename deque<_Tp, _Allocator>::const_reference deque<_Tp, _Allocator>::back() const _NOEXCEPT {
1591 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "deque::back called on an empty deque");
1592 size_type __p = size() + __start_ - 1;
1593 return *(*(__map_.begin() + __p / __block_size) + __p % __block_size);
1594}
1595
1596template <class _Tp, class _Allocator>
1597void deque<_Tp, _Allocator>::push_back(const value_type& __v) {
1598 allocator_type& __a = __alloc();
1599 if (__back_spare() == 0)
1600 __add_back_capacity();
1601 // __back_spare() >= 1
1602 __annotate_increase_back(n: 1);
1603 __alloc_traits::construct(__a, std::addressof(*end()), __v);
1604 ++__size();
1605}
1606
1607template <class _Tp, class _Allocator>
1608void deque<_Tp, _Allocator>::push_front(const value_type& __v) {
1609 allocator_type& __a = __alloc();
1610 if (__front_spare() == 0)
1611 __add_front_capacity();
1612 // __front_spare() >= 1
1613 __annotate_increase_front(n: 1);
1614 __alloc_traits::construct(__a, std::addressof(*--begin()), __v);
1615 --__start_;
1616 ++__size();
1617}
1618
1619# ifndef _LIBCPP_CXX03_LANG
1620template <class _Tp, class _Allocator>
1621void deque<_Tp, _Allocator>::push_back(value_type&& __v) {
1622 allocator_type& __a = __alloc();
1623 if (__back_spare() == 0)
1624 __add_back_capacity();
1625 // __back_spare() >= 1
1626 __annotate_increase_back(n: 1);
1627 __alloc_traits::construct(__a, std::addressof(*end()), std::move(__v));
1628 ++__size();
1629}
1630
1631template <class _Tp, class _Allocator>
1632template <class... _Args>
1633# if _LIBCPP_STD_VER >= 17
1634typename deque<_Tp, _Allocator>::reference
1635# else
1636void
1637# endif
1638deque<_Tp, _Allocator>::emplace_back(_Args&&... __args) {
1639 allocator_type& __a = __alloc();
1640 if (__back_spare() == 0)
1641 __add_back_capacity();
1642 // __back_spare() >= 1
1643 __annotate_increase_back(n: 1);
1644 __alloc_traits::construct(__a, std::addressof(*end()), std::forward<_Args>(__args)...);
1645 ++__size();
1646# if _LIBCPP_STD_VER >= 17
1647 return *--end();
1648# endif
1649}
1650
1651template <class _Tp, class _Allocator>
1652void deque<_Tp, _Allocator>::push_front(value_type&& __v) {
1653 allocator_type& __a = __alloc();
1654 if (__front_spare() == 0)
1655 __add_front_capacity();
1656 // __front_spare() >= 1
1657 __annotate_increase_front(n: 1);
1658 __alloc_traits::construct(__a, std::addressof(*--begin()), std::move(__v));
1659 --__start_;
1660 ++__size();
1661}
1662
1663template <class _Tp, class _Allocator>
1664template <class... _Args>
1665# if _LIBCPP_STD_VER >= 17
1666typename deque<_Tp, _Allocator>::reference
1667# else
1668void
1669# endif
1670deque<_Tp, _Allocator>::emplace_front(_Args&&... __args) {
1671 allocator_type& __a = __alloc();
1672 if (__front_spare() == 0)
1673 __add_front_capacity();
1674 // __front_spare() >= 1
1675 __annotate_increase_front(n: 1);
1676 __alloc_traits::construct(__a, std::addressof(*--begin()), std::forward<_Args>(__args)...);
1677 --__start_;
1678 ++__size();
1679# if _LIBCPP_STD_VER >= 17
1680 return *begin();
1681# endif
1682}
1683# endif // _LIBCPP_CXX03_LANG
1684
1685template <class _Tp, class _Allocator>
1686template <class... _Args>
1687typename deque<_Tp, _Allocator>::iterator deque<_Tp, _Allocator>::__emplace(const_iterator __p, _Args&&... __args) {
1688 size_type __pos = __p - begin();
1689 size_type __to_end = size() - __pos;
1690 allocator_type& __a = __alloc();
1691 if (__pos < __to_end) { // insert by shifting things backward
1692 if (__front_spare() == 0)
1693 __add_front_capacity();
1694 // __front_spare() >= 1
1695 __annotate_increase_front(n: 1);
1696 if (__pos == 0) {
1697 __alloc_traits::construct(__a, std::addressof(*--begin()), std::forward<_Args>(__args)...);
1698 --__start_;
1699 ++__size();
1700 } else {
1701 __temp_value<value_type, _Allocator> __tmp(__alloc(), std::forward<_Args>(__args)...);
1702 iterator __b = begin();
1703 iterator __bm1 = std::prev(__b);
1704 __alloc_traits::construct(__a, std::addressof(*__bm1), std::move(*__b));
1705 --__start_;
1706 ++__size();
1707 if (__pos > 1)
1708 __b = std::move(std::next(__b), __b + __pos, __b);
1709 *__b = std::move(__tmp.get());
1710 }
1711 } else { // insert by shifting things forward
1712 if (__back_spare() == 0)
1713 __add_back_capacity();
1714 // __back_capacity >= 1
1715 __annotate_increase_back(n: 1);
1716 size_type __de = size() - __pos;
1717 if (__de == 0) {
1718 __alloc_traits::construct(__a, std::addressof(*end()), std::forward<_Args>(__args)...);
1719 ++__size();
1720 } else {
1721 __temp_value<value_type, _Allocator> __tmp(__alloc(), std::forward<_Args>(__args)...);
1722 iterator __e = end();
1723 iterator __em1 = std::prev(__e);
1724 __alloc_traits::construct(__a, std::addressof(*__e), std::move(*__em1));
1725 ++__size();
1726 if (__de > 1)
1727 __e = std::move_backward(__e - __de, __em1, __e);
1728 *--__e = std::move(__tmp.get());
1729 }
1730 }
1731 return begin() + __pos;
1732}
1733
1734template <class _Tp, class _Allocator>
1735typename deque<_Tp, _Allocator>::iterator
1736deque<_Tp, _Allocator>::insert(const_iterator __p, size_type __n, const value_type& __v) {
1737 size_type __pos = __p - begin();
1738 size_type __to_end = __size() - __pos;
1739 allocator_type& __a = __alloc();
1740 if (__pos < __to_end) { // insert by shifting things backward
1741 if (__n > __front_spare())
1742 __add_front_capacity(__n - __front_spare());
1743 // __n <= __front_spare()
1744 __annotate_increase_front(__n);
1745 iterator __old_begin = begin();
1746 iterator __i = __old_begin;
1747 if (__n > __pos) {
1748 for (size_type __m = __n - __pos; __m; --__m, --__start_, ++__size())
1749 __alloc_traits::construct(__a, std::addressof(*--__i), __v);
1750 __n = __pos;
1751 }
1752 if (__n > 0) {
1753 const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v);
1754 iterator __obn = __old_begin + __n;
1755 __move_construct_backward_and_check(f: __old_begin, l: __obn, r: __i, __vt);
1756 if (__n < __pos)
1757 __old_begin = __move_and_check(f: __obn, l: __old_begin + __pos, r: __old_begin, __vt);
1758 std::fill_n(__old_begin, __n, *__vt);
1759 }
1760 } else { // insert by shifting things forward
1761 size_type __back_capacity = __back_spare();
1762 if (__n > __back_capacity)
1763 __add_back_capacity(__n - __back_capacity);
1764 // __n <= __back_capacity
1765 __annotate_increase_back(__n);
1766 iterator __old_end = end();
1767 iterator __i = __old_end;
1768 size_type __de = size() - __pos;
1769 if (__n > __de) {
1770 for (size_type __m = __n - __de; __m; --__m, (void)++__i, ++__size())
1771 __alloc_traits::construct(__a, std::addressof(*__i), __v);
1772 __n = __de;
1773 }
1774 if (__n > 0) {
1775 const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v);
1776 iterator __oen = __old_end - __n;
1777 __move_construct_and_check(f: __oen, l: __old_end, r: __i, __vt);
1778 if (__n < __de)
1779 __old_end = __move_backward_and_check(f: __old_end - __de, l: __oen, r: __old_end, __vt);
1780 std::fill_n(__old_end - __n, __n, *__vt);
1781 }
1782 }
1783 return begin() + __pos;
1784}
1785
1786template <class _Tp, class _Allocator>
1787template <class _InputIter, __enable_if_t<__has_exactly_input_iterator_category<_InputIter>::value, int> >
1788typename deque<_Tp, _Allocator>::iterator
1789deque<_Tp, _Allocator>::insert(const_iterator __p, _InputIter __f, _InputIter __l) {
1790 return __insert_with_sentinel(__p, __f, __l);
1791}
1792
1793template <class _Tp, class _Allocator>
1794template <class _Iterator, class _Sentinel>
1795_LIBCPP_HIDE_FROM_ABI typename deque<_Tp, _Allocator>::iterator
1796deque<_Tp, _Allocator>::__insert_with_sentinel(const_iterator __p, _Iterator __f, _Sentinel __l) {
1797 __split_buffer<value_type, allocator_type> __buf(__alloc());
1798 __buf.__construct_at_end_with_sentinel(std::move(__f), std::move(__l));
1799 typedef typename __split_buffer<value_type, allocator_type>::iterator __bi;
1800 return insert(__p, move_iterator<__bi>(__buf.begin()), move_iterator<__bi>(__buf.end()));
1801}
1802
1803template <class _Tp, class _Allocator>
1804template <class _ForwardIterator, __enable_if_t<__has_exactly_forward_iterator_category<_ForwardIterator>::value, int> >
1805typename deque<_Tp, _Allocator>::iterator
1806deque<_Tp, _Allocator>::insert(const_iterator __p, _ForwardIterator __f, _ForwardIterator __l) {
1807 return __insert_with_size(__p, __f, std::distance(__f, __l));
1808}
1809
1810template <class _Tp, class _Allocator>
1811template <class _Iterator>
1812_LIBCPP_HIDE_FROM_ABI typename deque<_Tp, _Allocator>::iterator
1813deque<_Tp, _Allocator>::__insert_with_size(const_iterator __p, _Iterator __f, size_type __n) {
1814 __split_buffer<value_type, allocator_type> __buf(__n, 0, __alloc());
1815 __buf.__construct_at_end_with_size(std::move(__f), __n);
1816 typedef typename __split_buffer<value_type, allocator_type>::iterator __fwd;
1817 return insert(__p, move_iterator<__fwd>(__buf.begin()), move_iterator<__fwd>(__buf.end()));
1818}
1819
1820template <class _Tp, class _Allocator>
1821template <class _BiIter, __enable_if_t<__has_bidirectional_iterator_category<_BiIter>::value, int> >
1822typename deque<_Tp, _Allocator>::iterator deque<_Tp, _Allocator>::insert(const_iterator __p, _BiIter __f, _BiIter __l) {
1823 return __insert_bidirectional(__p, __f, __l, std::distance(__f, __l));
1824}
1825
1826template <class _Tp, class _Allocator>
1827template <class _BiIter, class _Sentinel>
1828_LIBCPP_HIDE_FROM_ABI typename deque<_Tp, _Allocator>::iterator
1829deque<_Tp, _Allocator>::__insert_bidirectional(const_iterator __p, _BiIter __f, _Sentinel, size_type __n) {
1830 return __insert_bidirectional(__p, __f, std::next(__f, __n), __n);
1831}
1832
1833template <class _Tp, class _Allocator>
1834template <class _BiIter>
1835_LIBCPP_HIDE_FROM_ABI typename deque<_Tp, _Allocator>::iterator
1836deque<_Tp, _Allocator>::__insert_bidirectional(const_iterator __p, _BiIter __f, _BiIter __l, size_type __n) {
1837 size_type __pos = __p - begin();
1838 size_type __to_end = size() - __pos;
1839 allocator_type& __a = __alloc();
1840 if (__pos < __to_end) { // insert by shifting things backward
1841 if (__n > __front_spare())
1842 __add_front_capacity(__n - __front_spare());
1843 // __n <= __front_spare()
1844 __annotate_increase_front(__n);
1845 iterator __old_begin = begin();
1846 iterator __i = __old_begin;
1847 _BiIter __m = __f;
1848 if (__n > __pos) {
1849 __m = __pos < __n / 2 ? std::prev(__l, __pos) : std::next(__f, __n - __pos);
1850 for (_BiIter __j = __m; __j != __f; --__start_, ++__size())
1851 __alloc_traits::construct(__a, std::addressof(*--__i), *--__j);
1852 __n = __pos;
1853 }
1854 if (__n > 0) {
1855 iterator __obn = __old_begin + __n;
1856 for (iterator __j = __obn; __j != __old_begin;) {
1857 __alloc_traits::construct(__a, std::addressof(*--__i), std::move(*--__j));
1858 --__start_;
1859 ++__size();
1860 }
1861 if (__n < __pos)
1862 __old_begin = std::move(__obn, __old_begin + __pos, __old_begin);
1863 std::copy(__m, __l, __old_begin);
1864 }
1865 } else { // insert by shifting things forward
1866 size_type __back_capacity = __back_spare();
1867 if (__n > __back_capacity)
1868 __add_back_capacity(__n - __back_capacity);
1869 // __n <= __back_capacity
1870 __annotate_increase_back(__n);
1871 iterator __old_end = end();
1872 iterator __i = __old_end;
1873 _BiIter __m = __l;
1874 size_type __de = size() - __pos;
1875 if (__n > __de) {
1876 __m = __de < __n / 2 ? std::next(__f, __de) : std::prev(__l, __n - __de);
1877 for (_BiIter __j = __m; __j != __l; ++__i, (void)++__j, ++__size())
1878 __alloc_traits::construct(__a, std::addressof(*__i), *__j);
1879 __n = __de;
1880 }
1881 if (__n > 0) {
1882 iterator __oen = __old_end - __n;
1883 for (iterator __j = __oen; __j != __old_end; ++__i, (void)++__j, ++__size())
1884 __alloc_traits::construct(__a, std::addressof(*__i), std::move(*__j));
1885 if (__n < __de)
1886 __old_end = std::move_backward(__old_end - __de, __oen, __old_end);
1887 std::copy_backward(__f, __m, __old_end);
1888 }
1889 }
1890 return begin() + __pos;
1891}
1892
1893template <class _Tp, class _Allocator>
1894template <class _InpIter, __enable_if_t<__has_exactly_input_iterator_category<_InpIter>::value, int> >
1895void deque<_Tp, _Allocator>::__append(_InpIter __f, _InpIter __l) {
1896 __append_with_sentinel(__f, __l);
1897}
1898
1899template <class _Tp, class _Allocator>
1900template <class _InputIterator, class _Sentinel>
1901_LIBCPP_HIDE_FROM_ABI void deque<_Tp, _Allocator>::__append_with_sentinel(_InputIterator __f, _Sentinel __l) {
1902 for (; __f != __l; ++__f)
1903# ifdef _LIBCPP_CXX03_LANG
1904 push_back(*__f);
1905# else
1906 emplace_back(*__f);
1907# endif
1908}
1909
1910template <class _Tp, class _Allocator>
1911template <class _ForIter, __enable_if_t<__has_forward_iterator_category<_ForIter>::value, int> >
1912void deque<_Tp, _Allocator>::__append(_ForIter __f, _ForIter __l) {
1913 __append_with_size(__f, std::distance(__f, __l));
1914}
1915
1916template <class _Tp, class _Allocator>
1917template <class _InputIterator>
1918_LIBCPP_HIDE_FROM_ABI void deque<_Tp, _Allocator>::__append_with_size(_InputIterator __f, size_type __n) {
1919 allocator_type& __a = __alloc();
1920 size_type __back_capacity = __back_spare();
1921 if (__n > __back_capacity)
1922 __add_back_capacity(__n - __back_capacity);
1923
1924 // __n <= __back_capacity
1925 __annotate_increase_back(__n);
1926 for (__deque_block_range __br : __deque_range(end(), end() + __n)) {
1927 _ConstructTransaction __tx(this, __br);
1928 for (; __tx.__pos_ != __tx.__end_; ++__tx.__pos_, (void)++__f) {
1929 __alloc_traits::construct(__a, std::__to_address(__tx.__pos_), *__f);
1930 }
1931 }
1932}
1933
1934template <class _Tp, class _Allocator>
1935void deque<_Tp, _Allocator>::__append(size_type __n) {
1936 allocator_type& __a = __alloc();
1937 size_type __back_capacity = __back_spare();
1938 if (__n > __back_capacity)
1939 __add_back_capacity(__n - __back_capacity);
1940 // __n <= __back_capacity
1941 __annotate_increase_back(__n);
1942 for (__deque_block_range __br : __deque_range(end(), end() + __n)) {
1943 _ConstructTransaction __tx(this, __br);
1944 for (; __tx.__pos_ != __tx.__end_; ++__tx.__pos_) {
1945 __alloc_traits::construct(__a, std::__to_address(__tx.__pos_));
1946 }
1947 }
1948}
1949
1950template <class _Tp, class _Allocator>
1951void deque<_Tp, _Allocator>::__append(size_type __n, const value_type& __v) {
1952 allocator_type& __a = __alloc();
1953 size_type __back_capacity = __back_spare();
1954 if (__n > __back_capacity)
1955 __add_back_capacity(__n - __back_capacity);
1956 // __n <= __back_capacity
1957 __annotate_increase_back(__n);
1958 for (__deque_block_range __br : __deque_range(end(), end() + __n)) {
1959 _ConstructTransaction __tx(this, __br);
1960 for (; __tx.__pos_ != __tx.__end_; ++__tx.__pos_) {
1961 __alloc_traits::construct(__a, std::__to_address(__tx.__pos_), __v);
1962 }
1963 }
1964}
1965
1966// Create front capacity for one block of elements.
1967// Strong guarantee. Either do it or don't touch anything.
1968template <class _Tp, class _Allocator>
1969void deque<_Tp, _Allocator>::__add_front_capacity() {
1970 allocator_type& __a = __alloc();
1971 if (__back_spare() >= __block_size) {
1972 __start_ += __block_size;
1973 pointer __pt = __map_.back();
1974 __map_.pop_back();
1975 __map_.emplace_front(__pt);
1976 }
1977 // Else if __map_.size() < __map_.capacity() then we need to allocate 1 buffer
1978 else if (__map_.size() < __map_.capacity()) { // we can put the new buffer into the map, but don't shift things around
1979 // until all buffers are allocated. If we throw, we don't need to fix
1980 // anything up (any added buffers are undetectible)
1981 if (__map_.__front_spare() > 0)
1982 __map_.emplace_front(__alloc_traits::allocate(__a, __block_size));
1983 else {
1984 __map_.emplace_back(__alloc_traits::allocate(__a, __block_size));
1985 // Done allocating, reorder capacity
1986 pointer __pt = __map_.back();
1987 __map_.pop_back();
1988 __map_.emplace_front(__pt);
1989 }
1990 __start_ = __map_.size() == 1 ? __block_size / 2 : __start_ + __block_size;
1991 }
1992 // Else need to allocate 1 buffer, *and* we need to reallocate __map_.
1993 else {
1994 __split_buffer<pointer, __pointer_allocator> __buf(
1995 std::max<size_type>(2 * __map_.capacity(), 1), 0, __map_.__get_allocator());
1996
1997 typedef __allocator_destructor<_Allocator> _Dp;
1998 unique_ptr<pointer, _Dp> __hold(__alloc_traits::allocate(__a, __block_size), _Dp(__a, __block_size));
1999 __buf.emplace_back(__hold.get());
2000 __hold.release();
2001
2002 for (__map_pointer __i = __map_.begin(); __i != __map_.end(); ++__i)
2003 __buf.emplace_back(*__i);
2004 __map_.__swap_without_allocator(__buf);
2005 __start_ = __map_.size() == 1 ? __block_size / 2 : __start_ + __block_size;
2006 }
2007 __annotate_whole_block(block_index: 0, annotation_type: __asan_poison);
2008}
2009
2010// Create front capacity for __n elements.
2011// Strong guarantee. Either do it or don't touch anything.
2012template <class _Tp, class _Allocator>
2013void deque<_Tp, _Allocator>::__add_front_capacity(size_type __n) {
2014 allocator_type& __a = __alloc();
2015 size_type __nb = __recommend_blocks(n: __n + __map_.empty());
2016 // Number of unused blocks at back:
2017 size_type __back_capacity = __back_spare() / __block_size;
2018 __back_capacity = std::min(__back_capacity, __nb); // don't take more than you need
2019 __nb -= __back_capacity; // number of blocks need to allocate
2020 // If __nb == 0, then we have sufficient capacity.
2021 if (__nb == 0) {
2022 __start_ += __block_size * __back_capacity;
2023 for (; __back_capacity > 0; --__back_capacity) {
2024 pointer __pt = __map_.back();
2025 __map_.pop_back();
2026 __map_.emplace_front(__pt);
2027 }
2028 }
2029 // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers
2030 else if (__nb <= __map_.capacity() -
2031 __map_.size()) { // we can put the new buffers into the map, but don't shift things around
2032 // until all buffers are allocated. If we throw, we don't need to fix
2033 // anything up (any added buffers are undetectible)
2034 for (; __nb > 0; --__nb, __start_ += __block_size - (__map_.size() == 1)) {
2035 if (__map_.__front_spare() == 0)
2036 break;
2037 __map_.emplace_front(__alloc_traits::allocate(__a, __block_size));
2038 __annotate_whole_block(block_index: 0, annotation_type: __asan_poison);
2039 }
2040 for (; __nb > 0; --__nb, ++__back_capacity)
2041 __map_.emplace_back(__alloc_traits::allocate(__a, __block_size));
2042 // Done allocating, reorder capacity
2043 __start_ += __back_capacity * __block_size;
2044 for (; __back_capacity > 0; --__back_capacity) {
2045 pointer __pt = __map_.back();
2046 __map_.pop_back();
2047 __map_.emplace_front(__pt);
2048 __annotate_whole_block(block_index: 0, annotation_type: __asan_poison);
2049 }
2050 }
2051 // Else need to allocate __nb buffers, *and* we need to reallocate __map_.
2052 else {
2053 size_type __ds = (__nb + __back_capacity) * __block_size - __map_.empty();
2054 __split_buffer<pointer, __pointer_allocator> __buf(
2055 std::max<size_type>(2 * __map_.capacity(), __nb + __map_.size()), 0, __map_.__get_allocator());
2056 auto __guard = std::__make_exception_guard([&] {
2057 __annotate_delete();
2058 for (__map_pointer __i = __buf.begin(); __i != __buf.end(); ++__i)
2059 __alloc_traits::deallocate(__a, *__i, __block_size);
2060 });
2061 for (; __nb > 0; --__nb) {
2062 __buf.emplace_back(__alloc_traits::allocate(__a, __block_size));
2063 // ASan: this is empty container, we have to poison whole block
2064 __annotate_poison_block(beginning: std::__to_address(__buf.back()), end: std::__to_address(__buf.back() + __block_size));
2065 }
2066 __guard.__complete();
2067 for (; __back_capacity > 0; --__back_capacity) {
2068 __buf.emplace_back(__map_.back());
2069 __map_.pop_back();
2070 }
2071 for (__map_pointer __i = __map_.begin(); __i != __map_.end(); ++__i)
2072 __buf.emplace_back(*__i);
2073 __map_.__swap_without_allocator(__buf);
2074 __start_ += __ds;
2075 }
2076}
2077
2078// Create back capacity for one block of elements.
2079// Strong guarantee. Either do it or don't touch anything.
2080template <class _Tp, class _Allocator>
2081void deque<_Tp, _Allocator>::__add_back_capacity() {
2082 allocator_type& __a = __alloc();
2083 if (__front_spare() >= __block_size) {
2084 __start_ -= __block_size;
2085 pointer __pt = __map_.front();
2086 __map_.pop_front();
2087 __map_.emplace_back(__pt);
2088 }
2089 // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers
2090 else if (__map_.size() < __map_.capacity()) { // we can put the new buffer into the map, but don't shift things around
2091 // until it is allocated. If we throw, we don't need to fix
2092 // anything up (any added buffers are undetectible)
2093 if (__map_.__back_spare() != 0)
2094 __map_.emplace_back(__alloc_traits::allocate(__a, __block_size));
2095 else {
2096 __map_.emplace_front(__alloc_traits::allocate(__a, __block_size));
2097 // Done allocating, reorder capacity
2098 pointer __pt = __map_.front();
2099 __map_.pop_front();
2100 __map_.emplace_back(__pt);
2101 }
2102 __annotate_whole_block(block_index: __map_.size() - 1, annotation_type: __asan_poison);
2103 }
2104 // Else need to allocate 1 buffer, *and* we need to reallocate __map_.
2105 else {
2106 __split_buffer<pointer, __pointer_allocator> __buf(
2107 std::max<size_type>(2 * __map_.capacity(), 1), __map_.size(), __map_.__get_allocator());
2108
2109 typedef __allocator_destructor<_Allocator> _Dp;
2110 unique_ptr<pointer, _Dp> __hold(__alloc_traits::allocate(__a, __block_size), _Dp(__a, __block_size));
2111 __buf.emplace_back(__hold.get());
2112 __hold.release();
2113
2114 for (__map_pointer __i = __map_.end(); __i != __map_.begin();)
2115 __buf.emplace_front(*--__i);
2116 __map_.__swap_without_allocator(__buf);
2117 __annotate_whole_block(block_index: __map_.size() - 1, annotation_type: __asan_poison);
2118 }
2119}
2120
2121// Create back capacity for __n elements.
2122// Strong guarantee. Either do it or don't touch anything.
2123template <class _Tp, class _Allocator>
2124void deque<_Tp, _Allocator>::__add_back_capacity(size_type __n) {
2125 allocator_type& __a = __alloc();
2126 size_type __nb = __recommend_blocks(n: __n + __map_.empty());
2127 // Number of unused blocks at front:
2128 size_type __front_capacity = __front_spare() / __block_size;
2129 __front_capacity = std::min(__front_capacity, __nb); // don't take more than you need
2130 __nb -= __front_capacity; // number of blocks need to allocate
2131 // If __nb == 0, then we have sufficient capacity.
2132 if (__nb == 0) {
2133 __start_ -= __block_size * __front_capacity;
2134 for (; __front_capacity > 0; --__front_capacity) {
2135 pointer __pt = __map_.front();
2136 __map_.pop_front();
2137 __map_.emplace_back(__pt);
2138 }
2139 }
2140 // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers
2141 else if (__nb <= __map_.capacity() -
2142 __map_.size()) { // we can put the new buffers into the map, but don't shift things around
2143 // until all buffers are allocated. If we throw, we don't need to fix
2144 // anything up (any added buffers are undetectible)
2145 for (; __nb > 0; --__nb) {
2146 if (__map_.__back_spare() == 0)
2147 break;
2148 __map_.emplace_back(__alloc_traits::allocate(__a, __block_size));
2149 __annotate_whole_block(block_index: __map_.size() - 1, annotation_type: __asan_poison);
2150 }
2151 for (; __nb > 0; --__nb, ++__front_capacity, __start_ += __block_size - (__map_.size() == 1)) {
2152 __map_.emplace_front(__alloc_traits::allocate(__a, __block_size));
2153 __annotate_whole_block(block_index: 0, annotation_type: __asan_poison);
2154 }
2155 // Done allocating, reorder capacity
2156 __start_ -= __block_size * __front_capacity;
2157 for (; __front_capacity > 0; --__front_capacity) {
2158 pointer __pt = __map_.front();
2159 __map_.pop_front();
2160 __map_.emplace_back(__pt);
2161 }
2162 }
2163 // Else need to allocate __nb buffers, *and* we need to reallocate __map_.
2164 else {
2165 size_type __ds = __front_capacity * __block_size;
2166 __split_buffer<pointer, __pointer_allocator> __buf(
2167 std::max<size_type>(2 * __map_.capacity(), __nb + __map_.size()),
2168 __map_.size() - __front_capacity,
2169 __map_.__get_allocator());
2170 auto __guard = std::__make_exception_guard([&] {
2171 __annotate_delete();
2172 for (__map_pointer __i = __buf.begin(); __i != __buf.end(); ++__i)
2173 __alloc_traits::deallocate(__a, *__i, __block_size);
2174 });
2175 for (; __nb > 0; --__nb) {
2176 __buf.emplace_back(__alloc_traits::allocate(__a, __block_size));
2177 // ASan: this is an empty container, we have to poison the whole block
2178 __annotate_poison_block(beginning: std::__to_address(__buf.back()), end: std::__to_address(__buf.back() + __block_size));
2179 }
2180 __guard.__complete();
2181 for (; __front_capacity > 0; --__front_capacity) {
2182 __buf.emplace_back(__map_.front());
2183 __map_.pop_front();
2184 }
2185 for (__map_pointer __i = __map_.end(); __i != __map_.begin();)
2186 __buf.emplace_front(*--__i);
2187 __map_.__swap_without_allocator(__buf);
2188 __start_ -= __ds;
2189 }
2190}
2191
2192template <class _Tp, class _Allocator>
2193void deque<_Tp, _Allocator>::pop_front() {
2194 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "deque::pop_front called on an empty deque");
2195 size_type __old_sz = size();
2196 size_type __old_start = __start_;
2197 allocator_type& __a = __alloc();
2198 __alloc_traits::destroy(
2199 __a, std::__to_address(*(__map_.begin() + __start_ / __block_size) + __start_ % __block_size));
2200 --__size();
2201 ++__start_;
2202 __annotate_shrink_front(old_size: __old_sz, __old_start);
2203 __maybe_remove_front_spare();
2204}
2205
2206template <class _Tp, class _Allocator>
2207void deque<_Tp, _Allocator>::pop_back() {
2208 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "deque::pop_back called on an empty deque");
2209 size_type __old_sz = size();
2210 size_type __old_start = __start_;
2211 allocator_type& __a = __alloc();
2212 size_type __p = size() + __start_ - 1;
2213 __alloc_traits::destroy(__a, std::__to_address(*(__map_.begin() + __p / __block_size) + __p % __block_size));
2214 --__size();
2215 __annotate_shrink_back(old_size: __old_sz, __old_start);
2216 __maybe_remove_back_spare();
2217}
2218
2219// move assign [__f, __l) to [__r, __r + (__l-__f)).
2220// If __vt points into [__f, __l), then subtract (__f - __r) from __vt.
2221template <class _Tp, class _Allocator>
2222typename deque<_Tp, _Allocator>::iterator
2223deque<_Tp, _Allocator>::__move_and_check(iterator __f, iterator __l, iterator __r, const_pointer& __vt) {
2224 // as if
2225 // for (; __f != __l; ++__f, ++__r)
2226 // *__r = std::move(*__f);
2227 difference_type __n = __l - __f;
2228 while (__n > 0) {
2229 pointer __fb = __f.__ptr_;
2230 pointer __fe = *__f.__m_iter_ + __block_size;
2231 difference_type __bs = __fe - __fb;
2232 if (__bs > __n) {
2233 __bs = __n;
2234 __fe = __fb + __bs;
2235 }
2236 if (__fb <= __vt && __vt < __fe)
2237 __vt = (const_iterator(__f.__m_iter_, __vt) -= __f - __r).__ptr_;
2238 __r = std::move(__fb, __fe, __r);
2239 __n -= __bs;
2240 __f += __bs;
2241 }
2242 return __r;
2243}
2244
2245// move assign [__f, __l) to [__r - (__l-__f), __r) backwards.
2246// If __vt points into [__f, __l), then add (__r - __l) to __vt.
2247template <class _Tp, class _Allocator>
2248typename deque<_Tp, _Allocator>::iterator
2249deque<_Tp, _Allocator>::__move_backward_and_check(iterator __f, iterator __l, iterator __r, const_pointer& __vt) {
2250 // as if
2251 // while (__f != __l)
2252 // *--__r = std::move(*--__l);
2253 difference_type __n = __l - __f;
2254 while (__n > 0) {
2255 --__l;
2256 pointer __lb = *__l.__m_iter_;
2257 pointer __le = __l.__ptr_ + 1;
2258 difference_type __bs = __le - __lb;
2259 if (__bs > __n) {
2260 __bs = __n;
2261 __lb = __le - __bs;
2262 }
2263 if (__lb <= __vt && __vt < __le)
2264 __vt = (const_iterator(__l.__m_iter_, __vt) += __r - __l - 1).__ptr_;
2265 __r = std::move_backward(__lb, __le, __r);
2266 __n -= __bs;
2267 __l -= __bs - 1;
2268 }
2269 return __r;
2270}
2271
2272// move construct [__f, __l) to [__r, __r + (__l-__f)).
2273// If __vt points into [__f, __l), then add (__r - __f) to __vt.
2274template <class _Tp, class _Allocator>
2275void deque<_Tp, _Allocator>::__move_construct_and_check(iterator __f, iterator __l, iterator __r, const_pointer& __vt) {
2276 allocator_type& __a = __alloc();
2277 // as if
2278 // for (; __f != __l; ++__r, ++__f, ++__size())
2279 // __alloc_traits::construct(__a, std::addressof(*__r), std::move(*__f));
2280 difference_type __n = __l - __f;
2281 while (__n > 0) {
2282 pointer __fb = __f.__ptr_;
2283 pointer __fe = *__f.__m_iter_ + __block_size;
2284 difference_type __bs = __fe - __fb;
2285 if (__bs > __n) {
2286 __bs = __n;
2287 __fe = __fb + __bs;
2288 }
2289 if (__fb <= __vt && __vt < __fe)
2290 __vt = (const_iterator(__f.__m_iter_, __vt) += __r - __f).__ptr_;
2291 for (; __fb != __fe; ++__fb, ++__r, ++__size())
2292 __alloc_traits::construct(__a, std::addressof(*__r), std::move(*__fb));
2293 __n -= __bs;
2294 __f += __bs;
2295 }
2296}
2297
2298// move construct [__f, __l) to [__r - (__l-__f), __r) backwards.
2299// If __vt points into [__f, __l), then subtract (__l - __r) from __vt.
2300template <class _Tp, class _Allocator>
2301void deque<_Tp, _Allocator>::__move_construct_backward_and_check(
2302 iterator __f, iterator __l, iterator __r, const_pointer& __vt) {
2303 allocator_type& __a = __alloc();
2304 // as if
2305 // for (iterator __j = __l; __j != __f;)
2306 // {
2307 // __alloc_traitsconstruct(__a, std::addressof(*--__r), std::move(*--__j));
2308 // --__start_;
2309 // ++__size();
2310 // }
2311 difference_type __n = __l - __f;
2312 while (__n > 0) {
2313 --__l;
2314 pointer __lb = *__l.__m_iter_;
2315 pointer __le = __l.__ptr_ + 1;
2316 difference_type __bs = __le - __lb;
2317 if (__bs > __n) {
2318 __bs = __n;
2319 __lb = __le - __bs;
2320 }
2321 if (__lb <= __vt && __vt < __le)
2322 __vt = (const_iterator(__l.__m_iter_, __vt) -= __l - __r + 1).__ptr_;
2323 while (__le != __lb) {
2324 __alloc_traits::construct(__a, std::addressof(*--__r), std::move(*--__le));
2325 --__start_;
2326 ++__size();
2327 }
2328 __n -= __bs;
2329 __l -= __bs - 1;
2330 }
2331}
2332
2333template <class _Tp, class _Allocator>
2334typename deque<_Tp, _Allocator>::iterator deque<_Tp, _Allocator>::erase(const_iterator __f) {
2335 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
2336 __f != end(), "deque::erase(iterator) called with a non-dereferenceable iterator");
2337 size_type __old_sz = size();
2338 size_type __old_start = __start_;
2339 iterator __b = begin();
2340 difference_type __pos = __f - __b;
2341 iterator __p = __b + __pos;
2342 allocator_type& __a = __alloc();
2343 if (static_cast<size_type>(__pos) <= (size() - 1) / 2) { // erase from front
2344 std::move_backward(__b, __p, std::next(__p));
2345 __alloc_traits::destroy(__a, std::addressof(*__b));
2346 --__size();
2347 ++__start_;
2348 __annotate_shrink_front(old_size: __old_sz, __old_start);
2349 __maybe_remove_front_spare();
2350 } else { // erase from back
2351 iterator __i = std::move(std::next(__p), end(), __p);
2352 __alloc_traits::destroy(__a, std::addressof(*__i));
2353 --__size();
2354 __annotate_shrink_back(old_size: __old_sz, __old_start);
2355 __maybe_remove_back_spare();
2356 }
2357 return begin() + __pos;
2358}
2359
2360template <class _Tp, class _Allocator>
2361typename deque<_Tp, _Allocator>::iterator deque<_Tp, _Allocator>::erase(const_iterator __f, const_iterator __l) {
2362 _LIBCPP_ASSERT_VALID_INPUT_RANGE(__f <= __l, "deque::erase(first, last) called with an invalid range");
2363 size_type __old_sz = size();
2364 size_type __old_start = __start_;
2365 difference_type __n = __l - __f;
2366 iterator __b = begin();
2367 difference_type __pos = __f - __b;
2368 iterator __p = __b + __pos;
2369 if (__n > 0) {
2370 allocator_type& __a = __alloc();
2371 if (static_cast<size_type>(__pos) <= (size() - __n) / 2) { // erase from front
2372 iterator __i = std::move_backward(__b, __p, __p + __n);
2373 for (; __b != __i; ++__b)
2374 __alloc_traits::destroy(__a, std::addressof(*__b));
2375 __size() -= __n;
2376 __start_ += __n;
2377 __annotate_shrink_front(old_size: __old_sz, __old_start);
2378 while (__maybe_remove_front_spare()) {
2379 }
2380 } else { // erase from back
2381 iterator __i = std::move(__p + __n, end(), __p);
2382 for (iterator __e = end(); __i != __e; ++__i)
2383 __alloc_traits::destroy(__a, std::addressof(*__i));
2384 __size() -= __n;
2385 __annotate_shrink_back(old_size: __old_sz, __old_start);
2386 while (__maybe_remove_back_spare()) {
2387 }
2388 }
2389 }
2390 return begin() + __pos;
2391}
2392
2393template <class _Tp, class _Allocator>
2394void deque<_Tp, _Allocator>::__erase_to_end(const_iterator __f) {
2395 size_type __old_sz = size();
2396 size_type __old_start = __start_;
2397 iterator __e = end();
2398 difference_type __n = __e - __f;
2399 if (__n > 0) {
2400 allocator_type& __a = __alloc();
2401 iterator __b = begin();
2402 difference_type __pos = __f - __b;
2403 for (iterator __p = __b + __pos; __p != __e; ++__p)
2404 __alloc_traits::destroy(__a, std::addressof(*__p));
2405 __size() -= __n;
2406 __annotate_shrink_back(old_size: __old_sz, __old_start);
2407 while (__maybe_remove_back_spare()) {
2408 }
2409 }
2410}
2411
2412template <class _Tp, class _Allocator>
2413inline void deque<_Tp, _Allocator>::swap(deque& __c)
2414# if _LIBCPP_STD_VER >= 14
2415 _NOEXCEPT
2416# else
2417 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable_v<allocator_type>)
2418# endif
2419{
2420 __map_.swap(__c.__map_);
2421 std::swap(__start_, __c.__start_);
2422 std::swap(__size(), __c.__size());
2423 std::__swap_allocator(__alloc(), __c.__alloc());
2424}
2425
2426template <class _Tp, class _Allocator>
2427inline void deque<_Tp, _Allocator>::clear() _NOEXCEPT {
2428 __annotate_delete();
2429 allocator_type& __a = __alloc();
2430 for (iterator __i = begin(), __e = end(); __i != __e; ++__i)
2431 __alloc_traits::destroy(__a, std::addressof(*__i));
2432 __size() = 0;
2433 while (__map_.size() > 2) {
2434 __alloc_traits::deallocate(__a, __map_.front(), __block_size);
2435 __map_.pop_front();
2436 }
2437 switch (__map_.size()) {
2438 case 1:
2439 __start_ = __block_size / 2;
2440 break;
2441 case 2:
2442 __start_ = __block_size;
2443 break;
2444 }
2445 __annotate_new(current_size: 0);
2446}
2447
2448template <class _Tp, class _Allocator>
2449inline _LIBCPP_HIDE_FROM_ABI bool operator==(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) {
2450 const typename deque<_Tp, _Allocator>::size_type __sz = __x.size();
2451 return __sz == __y.size() && std::equal(__x.begin(), __x.end(), __y.begin());
2452}
2453
2454# if _LIBCPP_STD_VER <= 17
2455
2456template <class _Tp, class _Allocator>
2457inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) {
2458 return !(__x == __y);
2459}
2460
2461template <class _Tp, class _Allocator>
2462inline _LIBCPP_HIDE_FROM_ABI bool operator<(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) {
2463 return std::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
2464}
2465
2466template <class _Tp, class _Allocator>
2467inline _LIBCPP_HIDE_FROM_ABI bool operator>(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) {
2468 return __y < __x;
2469}
2470
2471template <class _Tp, class _Allocator>
2472inline _LIBCPP_HIDE_FROM_ABI bool operator>=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) {
2473 return !(__x < __y);
2474}
2475
2476template <class _Tp, class _Allocator>
2477inline _LIBCPP_HIDE_FROM_ABI bool operator<=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) {
2478 return !(__y < __x);
2479}
2480
2481# else // _LIBCPP_STD_VER <= 17
2482
2483template <class _Tp, class _Allocator>
2484_LIBCPP_HIDE_FROM_ABI __synth_three_way_result<_Tp>
2485operator<=>(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) {
2486 return std::lexicographical_compare_three_way(__x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way);
2487}
2488
2489# endif // _LIBCPP_STD_VER <= 17
2490
2491template <class _Tp, class _Allocator>
2492inline _LIBCPP_HIDE_FROM_ABI void swap(deque<_Tp, _Allocator>& __x, deque<_Tp, _Allocator>& __y)
2493 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) {
2494 __x.swap(__y);
2495}
2496
2497# if _LIBCPP_STD_VER >= 20
2498template <class _Tp, class _Allocator, class _Up>
2499inline _LIBCPP_HIDE_FROM_ABI typename deque<_Tp, _Allocator>::size_type
2500erase(deque<_Tp, _Allocator>& __c, const _Up& __v) {
2501 auto __old_size = __c.size();
2502 __c.erase(std::remove(__c.begin(), __c.end(), __v), __c.end());
2503 return __old_size - __c.size();
2504}
2505
2506template <class _Tp, class _Allocator, class _Predicate>
2507inline _LIBCPP_HIDE_FROM_ABI typename deque<_Tp, _Allocator>::size_type
2508erase_if(deque<_Tp, _Allocator>& __c, _Predicate __pred) {
2509 auto __old_size = __c.size();
2510 __c.erase(std::remove_if(__c.begin(), __c.end(), __pred), __c.end());
2511 return __old_size - __c.size();
2512}
2513
2514template <>
2515inline constexpr bool __format::__enable_insertable<std::deque<char>> = true;
2516# if _LIBCPP_HAS_WIDE_CHARACTERS
2517template <>
2518inline constexpr bool __format::__enable_insertable<std::deque<wchar_t>> = true;
2519# endif
2520
2521# endif // _LIBCPP_STD_VER >= 20
2522
2523template <class _Tp, class _Allocator>
2524struct __container_traits<deque<_Tp, _Allocator> > {
2525 // http://eel.is/c++draft/deque.modifiers#3
2526 // If an exception is thrown other than by the copy constructor, move constructor, assignment operator, or move
2527 // assignment operator of T, there are no effects. If an exception is thrown while inserting a single element at
2528 // either end, there are no effects. Otherwise, if an exception is thrown by the move constructor of a
2529 // non-Cpp17CopyInsertable T, the effects are unspecified.
2530 static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee =
2531 is_nothrow_move_constructible<_Tp>::value || __is_cpp17_copy_insertable_v<_Allocator>;
2532
2533 static _LIBCPP_CONSTEXPR const bool __reservable = false;
2534};
2535
2536_LIBCPP_END_NAMESPACE_STD
2537
2538# if _LIBCPP_STD_VER >= 17
2539_LIBCPP_BEGIN_NAMESPACE_STD
2540namespace pmr {
2541template <class _ValueT>
2542using deque _LIBCPP_AVAILABILITY_PMR = std::deque<_ValueT, polymorphic_allocator<_ValueT>>;
2543} // namespace pmr
2544_LIBCPP_END_NAMESPACE_STD
2545# endif
2546
2547_LIBCPP_POP_MACROS
2548
2549# if defined(_LIBCPP_KEEP_TRANSITIVE_INCLUDES_LLVM23) && _LIBCPP_STD_VER <= 20
2550# include <algorithm>
2551# include <atomic>
2552# include <concepts>
2553# include <cstdlib>
2554# include <functional>
2555# include <iosfwd>
2556# include <iterator>
2557# include <type_traits>
2558# include <typeinfo>
2559# endif
2560#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
2561
2562#endif // _LIBCPP_DEQUE
2563