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