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