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