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_VECTOR 11#define _LIBCPP_VECTOR 12 13/* 14 vector synopsis 15 16namespace std 17{ 18 19template <class T, class Allocator = allocator<T> > 20class vector 21{ 22public: 23 typedef T value_type; 24 typedef Allocator allocator_type; 25 typedef typename allocator_type::reference reference; 26 typedef typename allocator_type::const_reference const_reference; 27 typedef implementation-defined iterator; 28 typedef implementation-defined const_iterator; 29 typedef typename allocator_type::size_type size_type; 30 typedef typename allocator_type::difference_type difference_type; 31 typedef typename allocator_type::pointer pointer; 32 typedef typename allocator_type::const_pointer const_pointer; 33 typedef std::reverse_iterator<iterator> reverse_iterator; 34 typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 35 36 vector() 37 noexcept(is_nothrow_default_constructible<allocator_type>::value); 38 explicit vector(const allocator_type&); 39 explicit vector(size_type n); 40 explicit vector(size_type n, const allocator_type&); // C++14 41 vector(size_type n, const value_type& value, const allocator_type& = allocator_type()); 42 template <class InputIterator> 43 vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type()); 44 vector(const vector& x); 45 vector(vector&& x) 46 noexcept(is_nothrow_move_constructible<allocator_type>::value); 47 vector(initializer_list<value_type> il); 48 vector(initializer_list<value_type> il, const allocator_type& a); 49 ~vector(); 50 vector& operator=(const vector& x); 51 vector& operator=(vector&& x) 52 noexcept( 53 allocator_type::propagate_on_container_move_assignment::value || 54 allocator_type::is_always_equal::value); // C++17 55 vector& operator=(initializer_list<value_type> il); 56 template <class InputIterator> 57 void assign(InputIterator first, InputIterator last); 58 void assign(size_type n, const value_type& u); 59 void assign(initializer_list<value_type> il); 60 61 allocator_type get_allocator() const noexcept; 62 63 iterator begin() noexcept; 64 const_iterator begin() const noexcept; 65 iterator end() noexcept; 66 const_iterator end() const noexcept; 67 68 reverse_iterator rbegin() noexcept; 69 const_reverse_iterator rbegin() const noexcept; 70 reverse_iterator rend() noexcept; 71 const_reverse_iterator rend() const noexcept; 72 73 const_iterator cbegin() const noexcept; 74 const_iterator cend() const noexcept; 75 const_reverse_iterator crbegin() const noexcept; 76 const_reverse_iterator crend() const noexcept; 77 78 size_type size() const noexcept; 79 size_type max_size() const noexcept; 80 size_type capacity() const noexcept; 81 bool empty() const noexcept; 82 void reserve(size_type n); 83 void shrink_to_fit() noexcept; 84 85 reference operator[](size_type n); 86 const_reference operator[](size_type n) const; 87 reference at(size_type n); 88 const_reference at(size_type n) const; 89 90 reference front(); 91 const_reference front() const; 92 reference back(); 93 const_reference back() const; 94 95 value_type* data() noexcept; 96 const value_type* data() const noexcept; 97 98 void push_back(const value_type& x); 99 void push_back(value_type&& x); 100 template <class... Args> 101 reference emplace_back(Args&&... args); // reference in C++17 102 void pop_back(); 103 104 template <class... Args> iterator emplace(const_iterator position, Args&&... args); 105 iterator insert(const_iterator position, const value_type& x); 106 iterator insert(const_iterator position, value_type&& x); 107 iterator insert(const_iterator position, size_type n, const value_type& x); 108 template <class InputIterator> 109 iterator insert(const_iterator position, InputIterator first, InputIterator last); 110 iterator insert(const_iterator position, initializer_list<value_type> il); 111 112 iterator erase(const_iterator position); 113 iterator erase(const_iterator first, const_iterator last); 114 115 void clear() noexcept; 116 117 void resize(size_type sz); 118 void resize(size_type sz, const value_type& c); 119 120 void swap(vector&) 121 noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value || 122 allocator_traits<allocator_type>::is_always_equal::value); // C++17 123 124 bool __invariants() const; 125}; 126 127template <class Allocator = allocator<T> > 128class vector<bool, Allocator> 129{ 130public: 131 typedef bool value_type; 132 typedef Allocator allocator_type; 133 typedef implementation-defined iterator; 134 typedef implementation-defined const_iterator; 135 typedef typename allocator_type::size_type size_type; 136 typedef typename allocator_type::difference_type difference_type; 137 typedef iterator pointer; 138 typedef const_iterator const_pointer; 139 typedef std::reverse_iterator<iterator> reverse_iterator; 140 typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 141 142 class reference 143 { 144 public: 145 reference(const reference&) noexcept; 146 operator bool() const noexcept; 147 reference& operator=(bool x) noexcept; 148 reference& operator=(const reference& x) noexcept; 149 iterator operator&() const noexcept; 150 void flip() noexcept; 151 }; 152 153 class const_reference 154 { 155 public: 156 const_reference(const reference&) noexcept; 157 operator bool() const noexcept; 158 const_iterator operator&() const noexcept; 159 }; 160 161 vector() 162 noexcept(is_nothrow_default_constructible<allocator_type>::value); 163 explicit vector(const allocator_type&); 164 explicit vector(size_type n, const allocator_type& a = allocator_type()); // C++14 165 vector(size_type n, const value_type& value, const allocator_type& = allocator_type()); 166 template <class InputIterator> 167 vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type()); 168 vector(const vector& x); 169 vector(vector&& x) 170 noexcept(is_nothrow_move_constructible<allocator_type>::value); 171 vector(initializer_list<value_type> il); 172 vector(initializer_list<value_type> il, const allocator_type& a); 173 ~vector(); 174 vector& operator=(const vector& x); 175 vector& operator=(vector&& x) 176 noexcept( 177 allocator_type::propagate_on_container_move_assignment::value || 178 allocator_type::is_always_equal::value); // C++17 179 vector& operator=(initializer_list<value_type> il); 180 template <class InputIterator> 181 void assign(InputIterator first, InputIterator last); 182 void assign(size_type n, const value_type& u); 183 void assign(initializer_list<value_type> il); 184 185 allocator_type get_allocator() const noexcept; 186 187 iterator begin() noexcept; 188 const_iterator begin() const noexcept; 189 iterator end() noexcept; 190 const_iterator end() const noexcept; 191 192 reverse_iterator rbegin() noexcept; 193 const_reverse_iterator rbegin() const noexcept; 194 reverse_iterator rend() noexcept; 195 const_reverse_iterator rend() const noexcept; 196 197 const_iterator cbegin() const noexcept; 198 const_iterator cend() const noexcept; 199 const_reverse_iterator crbegin() const noexcept; 200 const_reverse_iterator crend() const noexcept; 201 202 size_type size() const noexcept; 203 size_type max_size() const noexcept; 204 size_type capacity() const noexcept; 205 bool empty() const noexcept; 206 void reserve(size_type n); 207 void shrink_to_fit() noexcept; 208 209 reference operator[](size_type n); 210 const_reference operator[](size_type n) const; 211 reference at(size_type n); 212 const_reference at(size_type n) const; 213 214 reference front(); 215 const_reference front() const; 216 reference back(); 217 const_reference back() const; 218 219 void push_back(const value_type& x); 220 template <class... Args> reference emplace_back(Args&&... args); // C++14; reference in C++17 221 void pop_back(); 222 223 template <class... Args> iterator emplace(const_iterator position, Args&&... args); // C++14 224 iterator insert(const_iterator position, const value_type& x); 225 iterator insert(const_iterator position, size_type n, const value_type& x); 226 template <class InputIterator> 227 iterator insert(const_iterator position, InputIterator first, InputIterator last); 228 iterator insert(const_iterator position, initializer_list<value_type> il); 229 230 iterator erase(const_iterator position); 231 iterator erase(const_iterator first, const_iterator last); 232 233 void clear() noexcept; 234 235 void resize(size_type sz); 236 void resize(size_type sz, value_type x); 237 238 void swap(vector&) 239 noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value || 240 allocator_traits<allocator_type>::is_always_equal::value); // C++17 241 void flip() noexcept; 242 243 bool __invariants() const; 244}; 245 246template <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>> 247 vector(InputIterator, InputIterator, Allocator = Allocator()) 248 -> vector<typename iterator_traits<InputIterator>::value_type, Allocator>; // C++17 249 250template <class Allocator> struct hash<std::vector<bool, Allocator>>; 251 252template <class T, class Allocator> bool operator==(const vector<T,Allocator>& x, const vector<T,Allocator>& y); 253template <class T, class Allocator> bool operator< (const vector<T,Allocator>& x, const vector<T,Allocator>& y); 254template <class T, class Allocator> bool operator!=(const vector<T,Allocator>& x, const vector<T,Allocator>& y); 255template <class T, class Allocator> bool operator> (const vector<T,Allocator>& x, const vector<T,Allocator>& y); 256template <class T, class Allocator> bool operator>=(const vector<T,Allocator>& x, const vector<T,Allocator>& y); 257template <class T, class Allocator> bool operator<=(const vector<T,Allocator>& x, const vector<T,Allocator>& y); 258 259template <class T, class Allocator> 260void swap(vector<T,Allocator>& x, vector<T,Allocator>& y) 261 noexcept(noexcept(x.swap(y))); 262 263template <class T, class Allocator, class U> 264typename vector<T, Allocator>::size_type 265erase(vector<T, Allocator>& c, const U& value); // C++20 266template <class T, class Allocator, class Predicate> 267typename vector<T, Allocator>::size_type 268erase_if(vector<T, Allocator>& c, Predicate pred); // C++20 269 270} // std 271 272*/ 273 274#include <__algorithm/copy.h> 275#include <__algorithm/equal.h> 276#include <__algorithm/fill_n.h> 277#include <__algorithm/lexicographical_compare.h> 278#include <__algorithm/remove.h> 279#include <__algorithm/remove_if.h> 280#include <__algorithm/rotate.h> 281#include <__algorithm/unwrap_iter.h> 282#include <__assert> 283#include <__bit_reference> 284#include <__config> 285#include <__debug> 286#include <__functional/hash.h> 287#include <__iterator/iterator_traits.h> 288#include <__iterator/wrap_iter.h> 289#include <__split_buffer> 290#include <__utility/forward.h> 291#include <__utility/move.h> 292#include <__utility/swap.h> 293#include <climits> 294#include <compare> 295#include <cstdlib> 296#include <cstring> 297#include <initializer_list> 298#include <iosfwd> // for forward declaration of vector 299#include <limits> 300#include <memory> 301#include <stdexcept> 302#include <type_traits> 303#include <version> 304 305#include <utility> // TODO: Remove this 306 307// TODO: remove these headers 308#include <__functional/binary_function.h> 309#include <__functional/invoke.h> 310#include <__functional/operations.h> 311#include <__functional/reference_wrapper.h> 312#include <__functional/unary_function.h> 313#include <__functional/weak_result_type.h> 314#include <typeinfo> 315 316#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 317# pragma GCC system_header 318#endif 319 320_LIBCPP_PUSH_MACROS 321#include <__undef_macros> 322 323 324_LIBCPP_BEGIN_NAMESPACE_STD 325 326template <class _Tp, class _Allocator /* = allocator<_Tp> */> 327class _LIBCPP_TEMPLATE_VIS vector 328{ 329private: 330 typedef allocator<_Tp> __default_allocator_type; 331public: 332 typedef vector __self; 333 typedef _Tp value_type; 334 typedef _Allocator allocator_type; 335 typedef allocator_traits<allocator_type> __alloc_traits; 336 typedef value_type& reference; 337 typedef const value_type& const_reference; 338 typedef typename __alloc_traits::size_type size_type; 339 typedef typename __alloc_traits::difference_type difference_type; 340 typedef typename __alloc_traits::pointer pointer; 341 typedef typename __alloc_traits::const_pointer const_pointer; 342 typedef __wrap_iter<pointer> iterator; 343 typedef __wrap_iter<const_pointer> const_iterator; 344 typedef _VSTD::reverse_iterator<iterator> reverse_iterator; 345 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; 346 347 static_assert((is_same<typename allocator_type::value_type, value_type>::value), 348 "Allocator::value_type must be same type as value_type"); 349 350 _LIBCPP_INLINE_VISIBILITY 351 vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) 352 { 353 _VSTD::__debug_db_insert_c(this); 354 } 355 _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a) 356#if _LIBCPP_STD_VER <= 14 357 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value) 358#else 359 _NOEXCEPT 360#endif 361 : __end_cap_(nullptr, __a) 362 { 363 _VSTD::__debug_db_insert_c(this); 364 } 365 explicit vector(size_type __n); 366#if _LIBCPP_STD_VER > 11 367 explicit vector(size_type __n, const allocator_type& __a); 368#endif 369 vector(size_type __n, const value_type& __x); 370 371 template <class = __enable_if_t<__is_allocator<_Allocator>::value> > 372 vector(size_type __n, const value_type& __x, const allocator_type& __a) 373 : __end_cap_(nullptr, __a) 374 { 375 _VSTD::__debug_db_insert_c(this); 376 if (__n > 0) 377 { 378 __vallocate(__n); 379 __construct_at_end(__n, __x); 380 } 381 } 382 383 template <class _InputIterator> 384 vector(_InputIterator __first, 385 typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value && 386 !__is_cpp17_forward_iterator<_InputIterator>::value && 387 is_constructible< 388 value_type, 389 typename iterator_traits<_InputIterator>::reference>::value, 390 _InputIterator>::type __last); 391 template <class _InputIterator> 392 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, 393 typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value && 394 !__is_cpp17_forward_iterator<_InputIterator>::value && 395 is_constructible< 396 value_type, 397 typename iterator_traits<_InputIterator>::reference>::value>::type* = 0); 398 template <class _ForwardIterator> 399 vector(_ForwardIterator __first, 400 typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value && 401 is_constructible< 402 value_type, 403 typename iterator_traits<_ForwardIterator>::reference>::value, 404 _ForwardIterator>::type __last); 405 template <class _ForwardIterator> 406 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, 407 typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value && 408 is_constructible< 409 value_type, 410 typename iterator_traits<_ForwardIterator>::reference>::value>::type* = 0); 411 412 _LIBCPP_INLINE_VISIBILITY 413 ~vector() 414 { 415 __annotate_delete(); 416#if _LIBCPP_DEBUG_LEVEL == 2 417 __get_db()->__erase_c(this); 418#endif 419 420 if (this->__begin_ != nullptr) 421 { 422 __clear(); 423 __alloc_traits::deallocate(__alloc(), this->__begin_, capacity()); 424 } 425 } 426 427 vector(const vector& __x); 428 vector(const vector& __x, const __identity_t<allocator_type>& __a); 429 _LIBCPP_INLINE_VISIBILITY 430 vector& operator=(const vector& __x); 431 432#ifndef _LIBCPP_CXX03_LANG 433 _LIBCPP_INLINE_VISIBILITY 434 vector(initializer_list<value_type> __il); 435 436 _LIBCPP_INLINE_VISIBILITY 437 vector(initializer_list<value_type> __il, const allocator_type& __a); 438 439 _LIBCPP_INLINE_VISIBILITY 440 vector(vector&& __x) 441#if _LIBCPP_STD_VER > 14 442 _NOEXCEPT; 443#else 444 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value); 445#endif 446 447 _LIBCPP_INLINE_VISIBILITY 448 vector(vector&& __x, const __identity_t<allocator_type>& __a); 449 _LIBCPP_INLINE_VISIBILITY 450 vector& operator=(vector&& __x) 451 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)); 452 453 _LIBCPP_INLINE_VISIBILITY 454 vector& operator=(initializer_list<value_type> __il) 455 {assign(__il.begin(), __il.end()); return *this;} 456 457#endif // !_LIBCPP_CXX03_LANG 458 459 template <class _InputIterator> 460 typename enable_if 461 < 462 __is_cpp17_input_iterator <_InputIterator>::value && 463 !__is_cpp17_forward_iterator<_InputIterator>::value && 464 is_constructible< 465 value_type, 466 typename iterator_traits<_InputIterator>::reference>::value, 467 void 468 >::type 469 assign(_InputIterator __first, _InputIterator __last); 470 template <class _ForwardIterator> 471 typename enable_if 472 < 473 __is_cpp17_forward_iterator<_ForwardIterator>::value && 474 is_constructible< 475 value_type, 476 typename iterator_traits<_ForwardIterator>::reference>::value, 477 void 478 >::type 479 assign(_ForwardIterator __first, _ForwardIterator __last); 480 481 void assign(size_type __n, const_reference __u); 482 483#ifndef _LIBCPP_CXX03_LANG 484 _LIBCPP_INLINE_VISIBILITY 485 void assign(initializer_list<value_type> __il) 486 {assign(__il.begin(), __il.end());} 487#endif 488 489 _LIBCPP_INLINE_VISIBILITY 490 allocator_type get_allocator() const _NOEXCEPT 491 {return this->__alloc();} 492 493 _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT; 494 _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT; 495 _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT; 496 _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT; 497 498 _LIBCPP_INLINE_VISIBILITY 499 reverse_iterator rbegin() _NOEXCEPT 500 {return reverse_iterator(end());} 501 _LIBCPP_INLINE_VISIBILITY 502 const_reverse_iterator rbegin() const _NOEXCEPT 503 {return const_reverse_iterator(end());} 504 _LIBCPP_INLINE_VISIBILITY 505 reverse_iterator rend() _NOEXCEPT 506 {return reverse_iterator(begin());} 507 _LIBCPP_INLINE_VISIBILITY 508 const_reverse_iterator rend() const _NOEXCEPT 509 {return const_reverse_iterator(begin());} 510 511 _LIBCPP_INLINE_VISIBILITY 512 const_iterator cbegin() const _NOEXCEPT 513 {return begin();} 514 _LIBCPP_INLINE_VISIBILITY 515 const_iterator cend() const _NOEXCEPT 516 {return end();} 517 _LIBCPP_INLINE_VISIBILITY 518 const_reverse_iterator crbegin() const _NOEXCEPT 519 {return rbegin();} 520 _LIBCPP_INLINE_VISIBILITY 521 const_reverse_iterator crend() const _NOEXCEPT 522 {return rend();} 523 524 _LIBCPP_INLINE_VISIBILITY 525 size_type size() const _NOEXCEPT 526 {return static_cast<size_type>(this->__end_ - this->__begin_);} 527 _LIBCPP_INLINE_VISIBILITY 528 size_type capacity() const _NOEXCEPT 529 {return static_cast<size_type>(__end_cap() - this->__begin_);} 530 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 531 bool empty() const _NOEXCEPT 532 {return this->__begin_ == this->__end_;} 533 size_type max_size() const _NOEXCEPT; 534 void reserve(size_type __n); 535 void shrink_to_fit() _NOEXCEPT; 536 537 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) _NOEXCEPT; 538 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const _NOEXCEPT; 539 reference at(size_type __n); 540 const_reference at(size_type __n) const; 541 542 _LIBCPP_INLINE_VISIBILITY reference front() _NOEXCEPT 543 { 544 _LIBCPP_ASSERT(!empty(), "front() called on an empty vector"); 545 return *this->__begin_; 546 } 547 _LIBCPP_INLINE_VISIBILITY const_reference front() const _NOEXCEPT 548 { 549 _LIBCPP_ASSERT(!empty(), "front() called on an empty vector"); 550 return *this->__begin_; 551 } 552 _LIBCPP_INLINE_VISIBILITY reference back() _NOEXCEPT 553 { 554 _LIBCPP_ASSERT(!empty(), "back() called on an empty vector"); 555 return *(this->__end_ - 1); 556 } 557 _LIBCPP_INLINE_VISIBILITY const_reference back() const _NOEXCEPT 558 { 559 _LIBCPP_ASSERT(!empty(), "back() called on an empty vector"); 560 return *(this->__end_ - 1); 561 } 562 563 _LIBCPP_INLINE_VISIBILITY 564 value_type* data() _NOEXCEPT 565 {return _VSTD::__to_address(this->__begin_);} 566 _LIBCPP_INLINE_VISIBILITY 567 const value_type* data() const _NOEXCEPT 568 {return _VSTD::__to_address(this->__begin_);} 569 570#ifdef _LIBCPP_CXX03_LANG 571 _LIBCPP_INLINE_VISIBILITY 572 void __emplace_back(const value_type& __x) { push_back(__x); } 573#else 574 template <class _Arg> 575 _LIBCPP_INLINE_VISIBILITY 576 void __emplace_back(_Arg&& __arg) { 577 emplace_back(_VSTD::forward<_Arg>(__arg)); 578 } 579#endif 580 581 _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x); 582 583#ifndef _LIBCPP_CXX03_LANG 584 _LIBCPP_INLINE_VISIBILITY void push_back(value_type&& __x); 585 586 template <class... _Args> 587 _LIBCPP_INLINE_VISIBILITY 588#if _LIBCPP_STD_VER > 14 589 reference emplace_back(_Args&&... __args); 590#else 591 void emplace_back(_Args&&... __args); 592#endif 593#endif // !_LIBCPP_CXX03_LANG 594 595 _LIBCPP_INLINE_VISIBILITY 596 void pop_back(); 597 598 iterator insert(const_iterator __position, const_reference __x); 599 600#ifndef _LIBCPP_CXX03_LANG 601 iterator insert(const_iterator __position, value_type&& __x); 602 template <class... _Args> 603 iterator emplace(const_iterator __position, _Args&&... __args); 604#endif // !_LIBCPP_CXX03_LANG 605 606 iterator insert(const_iterator __position, size_type __n, const_reference __x); 607 template <class _InputIterator> 608 typename enable_if 609 < 610 __is_cpp17_input_iterator <_InputIterator>::value && 611 !__is_cpp17_forward_iterator<_InputIterator>::value && 612 is_constructible< 613 value_type, 614 typename iterator_traits<_InputIterator>::reference>::value, 615 iterator 616 >::type 617 insert(const_iterator __position, _InputIterator __first, _InputIterator __last); 618 template <class _ForwardIterator> 619 typename enable_if 620 < 621 __is_cpp17_forward_iterator<_ForwardIterator>::value && 622 is_constructible< 623 value_type, 624 typename iterator_traits<_ForwardIterator>::reference>::value, 625 iterator 626 >::type 627 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last); 628 629#ifndef _LIBCPP_CXX03_LANG 630 _LIBCPP_INLINE_VISIBILITY 631 iterator insert(const_iterator __position, initializer_list<value_type> __il) 632 {return insert(__position, __il.begin(), __il.end());} 633#endif 634 635 _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position); 636 iterator erase(const_iterator __first, const_iterator __last); 637 638 _LIBCPP_INLINE_VISIBILITY 639 void clear() _NOEXCEPT 640 { 641 size_type __old_size = size(); 642 __clear(); 643 __annotate_shrink(__old_size); 644 __invalidate_all_iterators(); 645 } 646 647 void resize(size_type __sz); 648 void resize(size_type __sz, const_reference __x); 649 650 void swap(vector&) 651#if _LIBCPP_STD_VER >= 14 652 _NOEXCEPT; 653#else 654 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || 655 __is_nothrow_swappable<allocator_type>::value); 656#endif 657 658 bool __invariants() const; 659 660#if _LIBCPP_DEBUG_LEVEL == 2 661 662 bool __dereferenceable(const const_iterator* __i) const; 663 bool __decrementable(const const_iterator* __i) const; 664 bool __addable(const const_iterator* __i, ptrdiff_t __n) const; 665 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const; 666 667#endif // _LIBCPP_DEBUG_LEVEL == 2 668 669private: 670 pointer __begin_ = nullptr; 671 pointer __end_ = nullptr; 672 __compressed_pair<pointer, allocator_type> __end_cap_ = 673 __compressed_pair<pointer, allocator_type>(nullptr, __default_init_tag()); 674 675 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators(); 676 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(pointer __new_last); 677 void __vallocate(size_type __n); 678 void __vdeallocate() _NOEXCEPT; 679 _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const; 680 void __construct_at_end(size_type __n); 681 _LIBCPP_INLINE_VISIBILITY 682 void __construct_at_end(size_type __n, const_reference __x); 683 template <class _ForwardIterator> 684 typename enable_if 685 < 686 __is_cpp17_forward_iterator<_ForwardIterator>::value, 687 void 688 >::type 689 __construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n); 690 void __append(size_type __n); 691 void __append(size_type __n, const_reference __x); 692 _LIBCPP_INLINE_VISIBILITY 693 iterator __make_iter(pointer __p) _NOEXCEPT; 694 _LIBCPP_INLINE_VISIBILITY 695 const_iterator __make_iter(const_pointer __p) const _NOEXCEPT; 696 void __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v); 697 pointer __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p); 698 void __move_range(pointer __from_s, pointer __from_e, pointer __to); 699 void __move_assign(vector& __c, true_type) 700 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); 701 void __move_assign(vector& __c, false_type) 702 _NOEXCEPT_(__alloc_traits::is_always_equal::value); 703 _LIBCPP_INLINE_VISIBILITY 704 void __destruct_at_end(pointer __new_last) _NOEXCEPT 705 { 706 __invalidate_iterators_past(__new_last); 707 size_type __old_size = size(); 708 __base_destruct_at_end(__new_last); 709 __annotate_shrink(__old_size); 710 } 711 712#ifndef _LIBCPP_CXX03_LANG 713 template <class _Up> 714 _LIBCPP_INLINE_VISIBILITY 715 inline void __push_back_slow_path(_Up&& __x); 716 717 template <class... _Args> 718 _LIBCPP_INLINE_VISIBILITY 719 inline void __emplace_back_slow_path(_Args&&... __args); 720#else 721 template <class _Up> 722 _LIBCPP_INLINE_VISIBILITY 723 inline void __push_back_slow_path(_Up& __x); 724#endif 725 726 // The following functions are no-ops outside of AddressSanitizer mode. 727 // We call annotatations only for the default Allocator because other allocators 728 // may not meet the AddressSanitizer alignment constraints. 729 // See the documentation for __sanitizer_annotate_contiguous_container for more details. 730#ifndef _LIBCPP_HAS_NO_ASAN 731 void __annotate_contiguous_container(const void *__beg, const void *__end, 732 const void *__old_mid, 733 const void *__new_mid) const 734 { 735 736 if (__beg && is_same<allocator_type, __default_allocator_type>::value) 737 __sanitizer_annotate_contiguous_container(__beg, __end, __old_mid, __new_mid); 738 } 739#else 740 _LIBCPP_INLINE_VISIBILITY 741 void __annotate_contiguous_container(const void*, const void*, const void*, 742 const void*) const _NOEXCEPT {} 743#endif 744 _LIBCPP_INLINE_VISIBILITY 745 void __annotate_new(size_type __current_size) const _NOEXCEPT { 746 __annotate_contiguous_container(data(), data() + capacity(), 747 data() + capacity(), data() + __current_size); 748 } 749 750 _LIBCPP_INLINE_VISIBILITY 751 void __annotate_delete() const _NOEXCEPT { 752 __annotate_contiguous_container(data(), data() + capacity(), 753 data() + size(), data() + capacity()); 754 } 755 756 _LIBCPP_INLINE_VISIBILITY 757 void __annotate_increase(size_type __n) const _NOEXCEPT 758 { 759 __annotate_contiguous_container(data(), data() + capacity(), 760 data() + size(), data() + size() + __n); 761 } 762 763 _LIBCPP_INLINE_VISIBILITY 764 void __annotate_shrink(size_type __old_size) const _NOEXCEPT 765 { 766 __annotate_contiguous_container(data(), data() + capacity(), 767 data() + __old_size, data() + size()); 768 } 769 770 struct _ConstructTransaction { 771 explicit _ConstructTransaction(vector &__v, size_type __n) 772 : __v_(__v), __pos_(__v.__end_), __new_end_(__v.__end_ + __n) { 773#ifndef _LIBCPP_HAS_NO_ASAN 774 __v_.__annotate_increase(__n); 775#endif 776 } 777 ~_ConstructTransaction() { 778 __v_.__end_ = __pos_; 779#ifndef _LIBCPP_HAS_NO_ASAN 780 if (__pos_ != __new_end_) { 781 __v_.__annotate_shrink(__new_end_ - __v_.__begin_); 782 } 783#endif 784 } 785 786 vector &__v_; 787 pointer __pos_; 788 const_pointer const __new_end_; 789 790 private: 791 _ConstructTransaction(_ConstructTransaction const&) = delete; 792 _ConstructTransaction& operator=(_ConstructTransaction const&) = delete; 793 }; 794 795 template <class ..._Args> 796 _LIBCPP_INLINE_VISIBILITY 797 void __construct_one_at_end(_Args&& ...__args) { 798 _ConstructTransaction __tx(*this, 1); 799 __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__tx.__pos_), 800 _VSTD::forward<_Args>(__args)...); 801 ++__tx.__pos_; 802 } 803 804 _LIBCPP_INLINE_VISIBILITY 805 allocator_type& __alloc() _NOEXCEPT 806 {return this->__end_cap_.second();} 807 _LIBCPP_INLINE_VISIBILITY 808 const allocator_type& __alloc() const _NOEXCEPT 809 {return this->__end_cap_.second();} 810 _LIBCPP_INLINE_VISIBILITY 811 pointer& __end_cap() _NOEXCEPT 812 {return this->__end_cap_.first();} 813 _LIBCPP_INLINE_VISIBILITY 814 const pointer& __end_cap() const _NOEXCEPT 815 {return this->__end_cap_.first();} 816 817 _LIBCPP_INLINE_VISIBILITY 818 void __clear() _NOEXCEPT {__base_destruct_at_end(this->__begin_);} 819 820 _LIBCPP_INLINE_VISIBILITY 821 void __base_destruct_at_end(pointer __new_last) _NOEXCEPT { 822 pointer __soon_to_be_end = this->__end_; 823 while (__new_last != __soon_to_be_end) 824 __alloc_traits::destroy(__alloc(), _VSTD::__to_address(--__soon_to_be_end)); 825 this->__end_ = __new_last; 826 } 827 828 _LIBCPP_INLINE_VISIBILITY 829 void __copy_assign_alloc(const vector& __c) 830 {__copy_assign_alloc(__c, integral_constant<bool, 831 __alloc_traits::propagate_on_container_copy_assignment::value>());} 832 833 _LIBCPP_INLINE_VISIBILITY 834 void __move_assign_alloc(vector& __c) 835 _NOEXCEPT_( 836 !__alloc_traits::propagate_on_container_move_assignment::value || 837 is_nothrow_move_assignable<allocator_type>::value) 838 {__move_assign_alloc(__c, integral_constant<bool, 839 __alloc_traits::propagate_on_container_move_assignment::value>());} 840 841 _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI 842 void __throw_length_error() const { 843 _VSTD::__throw_length_error("vector"); 844 } 845 846 _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI 847 void __throw_out_of_range() const { 848 _VSTD::__throw_out_of_range("vector"); 849 } 850 851 _LIBCPP_INLINE_VISIBILITY 852 void __copy_assign_alloc(const vector& __c, true_type) 853 { 854 if (__alloc() != __c.__alloc()) 855 { 856 __clear(); 857 __alloc_traits::deallocate(__alloc(), this->__begin_, capacity()); 858 this->__begin_ = this->__end_ = __end_cap() = nullptr; 859 } 860 __alloc() = __c.__alloc(); 861 } 862 863 _LIBCPP_INLINE_VISIBILITY 864 void __copy_assign_alloc(const vector&, false_type) 865 {} 866 867 _LIBCPP_INLINE_VISIBILITY 868 void __move_assign_alloc(vector& __c, true_type) 869 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) 870 { 871 __alloc() = _VSTD::move(__c.__alloc()); 872 } 873 874 _LIBCPP_INLINE_VISIBILITY 875 void __move_assign_alloc(vector&, false_type) 876 _NOEXCEPT 877 {} 878}; 879 880#if _LIBCPP_STD_VER >= 17 881template<class _InputIterator, 882 class _Alloc = allocator<__iter_value_type<_InputIterator>>, 883 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>, 884 class = enable_if_t<__is_allocator<_Alloc>::value> 885 > 886vector(_InputIterator, _InputIterator) 887 -> vector<__iter_value_type<_InputIterator>, _Alloc>; 888 889template<class _InputIterator, 890 class _Alloc, 891 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>, 892 class = enable_if_t<__is_allocator<_Alloc>::value> 893 > 894vector(_InputIterator, _InputIterator, _Alloc) 895 -> vector<__iter_value_type<_InputIterator>, _Alloc>; 896#endif 897 898template <class _Tp, class _Allocator> 899void 900vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v) 901{ 902 903 __annotate_delete(); 904 _VSTD::__construct_backward_with_exception_guarantees(this->__alloc(), this->__begin_, this->__end_, __v.__begin_); 905 _VSTD::swap(this->__begin_, __v.__begin_); 906 _VSTD::swap(this->__end_, __v.__end_); 907 _VSTD::swap(this->__end_cap(), __v.__end_cap()); 908 __v.__first_ = __v.__begin_; 909 __annotate_new(size()); 910 __invalidate_all_iterators(); 911} 912 913template <class _Tp, class _Allocator> 914typename vector<_Tp, _Allocator>::pointer 915vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p) 916{ 917 __annotate_delete(); 918 pointer __r = __v.__begin_; 919 _VSTD::__construct_backward_with_exception_guarantees(this->__alloc(), this->__begin_, __p, __v.__begin_); 920 _VSTD::__construct_forward_with_exception_guarantees(this->__alloc(), __p, this->__end_, __v.__end_); 921 _VSTD::swap(this->__begin_, __v.__begin_); 922 _VSTD::swap(this->__end_, __v.__end_); 923 _VSTD::swap(this->__end_cap(), __v.__end_cap()); 924 __v.__first_ = __v.__begin_; 925 __annotate_new(size()); 926 __invalidate_all_iterators(); 927 return __r; 928} 929 930// Allocate space for __n objects 931// throws length_error if __n > max_size() 932// throws (probably bad_alloc) if memory run out 933// Precondition: __begin_ == __end_ == __end_cap() == 0 934// Precondition: __n > 0 935// Postcondition: capacity() == __n 936// Postcondition: size() == 0 937template <class _Tp, class _Allocator> 938void 939vector<_Tp, _Allocator>::__vallocate(size_type __n) 940{ 941 if (__n > max_size()) 942 this->__throw_length_error(); 943 this->__begin_ = this->__end_ = __alloc_traits::allocate(this->__alloc(), __n); 944 this->__end_cap() = this->__begin_ + __n; 945 __annotate_new(0); 946} 947 948template <class _Tp, class _Allocator> 949void 950vector<_Tp, _Allocator>::__vdeallocate() _NOEXCEPT 951{ 952 if (this->__begin_ != nullptr) 953 { 954 clear(); 955 __alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity()); 956 this->__begin_ = this->__end_ = this->__end_cap() = nullptr; 957 } 958} 959 960template <class _Tp, class _Allocator> 961typename vector<_Tp, _Allocator>::size_type 962vector<_Tp, _Allocator>::max_size() const _NOEXCEPT 963{ 964 return _VSTD::min<size_type>(__alloc_traits::max_size(this->__alloc()), 965 numeric_limits<difference_type>::max()); 966} 967 968// Precondition: __new_size > capacity() 969template <class _Tp, class _Allocator> 970inline _LIBCPP_INLINE_VISIBILITY 971typename vector<_Tp, _Allocator>::size_type 972vector<_Tp, _Allocator>::__recommend(size_type __new_size) const 973{ 974 const size_type __ms = max_size(); 975 if (__new_size > __ms) 976 this->__throw_length_error(); 977 const size_type __cap = capacity(); 978 if (__cap >= __ms / 2) 979 return __ms; 980 return _VSTD::max<size_type>(2 * __cap, __new_size); 981} 982 983// Default constructs __n objects starting at __end_ 984// throws if construction throws 985// Precondition: __n > 0 986// Precondition: size() + __n <= capacity() 987// Postcondition: size() == size() + __n 988template <class _Tp, class _Allocator> 989void 990vector<_Tp, _Allocator>::__construct_at_end(size_type __n) 991{ 992 _ConstructTransaction __tx(*this, __n); 993 const_pointer __new_end = __tx.__new_end_; 994 for (pointer __pos = __tx.__pos_; __pos != __new_end; __tx.__pos_ = ++__pos) { 995 __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__pos)); 996 } 997} 998 999// Copy constructs __n objects starting at __end_ from __x 1000// throws if construction throws 1001// Precondition: __n > 0 1002// Precondition: size() + __n <= capacity() 1003// Postcondition: size() == old size() + __n 1004// Postcondition: [i] == __x for all i in [size() - __n, __n) 1005template <class _Tp, class _Allocator> 1006inline 1007void 1008vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x) 1009{ 1010 _ConstructTransaction __tx(*this, __n); 1011 const_pointer __new_end = __tx.__new_end_; 1012 for (pointer __pos = __tx.__pos_; __pos != __new_end; __tx.__pos_ = ++__pos) { 1013 __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__pos), __x); 1014 } 1015} 1016 1017template <class _Tp, class _Allocator> 1018template <class _ForwardIterator> 1019typename enable_if 1020< 1021 __is_cpp17_forward_iterator<_ForwardIterator>::value, 1022 void 1023>::type 1024vector<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n) 1025{ 1026 _ConstructTransaction __tx(*this, __n); 1027 _VSTD::__construct_range_forward(this->__alloc(), __first, __last, __tx.__pos_); 1028} 1029 1030// Default constructs __n objects starting at __end_ 1031// throws if construction throws 1032// Postcondition: size() == size() + __n 1033// Exception safety: strong. 1034template <class _Tp, class _Allocator> 1035void 1036vector<_Tp, _Allocator>::__append(size_type __n) 1037{ 1038 if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n) 1039 this->__construct_at_end(__n); 1040 else 1041 { 1042 allocator_type& __a = this->__alloc(); 1043 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a); 1044 __v.__construct_at_end(__n); 1045 __swap_out_circular_buffer(__v); 1046 } 1047} 1048 1049// Default constructs __n objects starting at __end_ 1050// throws if construction throws 1051// Postcondition: size() == size() + __n 1052// Exception safety: strong. 1053template <class _Tp, class _Allocator> 1054void 1055vector<_Tp, _Allocator>::__append(size_type __n, const_reference __x) 1056{ 1057 if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n) 1058 this->__construct_at_end(__n, __x); 1059 else 1060 { 1061 allocator_type& __a = this->__alloc(); 1062 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a); 1063 __v.__construct_at_end(__n, __x); 1064 __swap_out_circular_buffer(__v); 1065 } 1066} 1067 1068template <class _Tp, class _Allocator> 1069vector<_Tp, _Allocator>::vector(size_type __n) 1070{ 1071 _VSTD::__debug_db_insert_c(this); 1072 if (__n > 0) 1073 { 1074 __vallocate(__n); 1075 __construct_at_end(__n); 1076 } 1077} 1078 1079#if _LIBCPP_STD_VER > 11 1080template <class _Tp, class _Allocator> 1081vector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a) 1082 : __end_cap_(nullptr, __a) 1083{ 1084 _VSTD::__debug_db_insert_c(this); 1085 if (__n > 0) 1086 { 1087 __vallocate(__n); 1088 __construct_at_end(__n); 1089 } 1090} 1091#endif 1092 1093template <class _Tp, class _Allocator> 1094vector<_Tp, _Allocator>::vector(size_type __n, const value_type& __x) 1095{ 1096 _VSTD::__debug_db_insert_c(this); 1097 if (__n > 0) 1098 { 1099 __vallocate(__n); 1100 __construct_at_end(__n, __x); 1101 } 1102} 1103 1104template <class _Tp, class _Allocator> 1105template <class _InputIterator> 1106vector<_Tp, _Allocator>::vector(_InputIterator __first, 1107 typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value && 1108 !__is_cpp17_forward_iterator<_InputIterator>::value && 1109 is_constructible< 1110 value_type, 1111 typename iterator_traits<_InputIterator>::reference>::value, 1112 _InputIterator>::type __last) 1113{ 1114 _VSTD::__debug_db_insert_c(this); 1115 for (; __first != __last; ++__first) 1116 __emplace_back(*__first); 1117} 1118 1119template <class _Tp, class _Allocator> 1120template <class _InputIterator> 1121vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, 1122 typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value && 1123 !__is_cpp17_forward_iterator<_InputIterator>::value && 1124 is_constructible< 1125 value_type, 1126 typename iterator_traits<_InputIterator>::reference>::value>::type*) 1127 : __end_cap_(nullptr, __a) 1128{ 1129 _VSTD::__debug_db_insert_c(this); 1130 for (; __first != __last; ++__first) 1131 __emplace_back(*__first); 1132} 1133 1134template <class _Tp, class _Allocator> 1135template <class _ForwardIterator> 1136vector<_Tp, _Allocator>::vector(_ForwardIterator __first, 1137 typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value && 1138 is_constructible< 1139 value_type, 1140 typename iterator_traits<_ForwardIterator>::reference>::value, 1141 _ForwardIterator>::type __last) 1142{ 1143 _VSTD::__debug_db_insert_c(this); 1144 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); 1145 if (__n > 0) 1146 { 1147 __vallocate(__n); 1148 __construct_at_end(__first, __last, __n); 1149 } 1150} 1151 1152template <class _Tp, class _Allocator> 1153template <class _ForwardIterator> 1154vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, 1155 typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value && 1156 is_constructible< 1157 value_type, 1158 typename iterator_traits<_ForwardIterator>::reference>::value>::type*) 1159 : __end_cap_(nullptr, __a) 1160{ 1161 _VSTD::__debug_db_insert_c(this); 1162 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); 1163 if (__n > 0) 1164 { 1165 __vallocate(__n); 1166 __construct_at_end(__first, __last, __n); 1167 } 1168} 1169 1170template <class _Tp, class _Allocator> 1171vector<_Tp, _Allocator>::vector(const vector& __x) 1172 : __end_cap_(nullptr, __alloc_traits::select_on_container_copy_construction(__x.__alloc())) 1173{ 1174 _VSTD::__debug_db_insert_c(this); 1175 size_type __n = __x.size(); 1176 if (__n > 0) 1177 { 1178 __vallocate(__n); 1179 __construct_at_end(__x.__begin_, __x.__end_, __n); 1180 } 1181} 1182 1183template <class _Tp, class _Allocator> 1184vector<_Tp, _Allocator>::vector(const vector& __x, const __identity_t<allocator_type>& __a) 1185 : __end_cap_(nullptr, __a) 1186{ 1187 _VSTD::__debug_db_insert_c(this); 1188 size_type __n = __x.size(); 1189 if (__n > 0) 1190 { 1191 __vallocate(__n); 1192 __construct_at_end(__x.__begin_, __x.__end_, __n); 1193 } 1194} 1195 1196#ifndef _LIBCPP_CXX03_LANG 1197 1198template <class _Tp, class _Allocator> 1199inline _LIBCPP_INLINE_VISIBILITY 1200vector<_Tp, _Allocator>::vector(vector&& __x) 1201#if _LIBCPP_STD_VER > 14 1202 _NOEXCEPT 1203#else 1204 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) 1205#endif 1206 : __end_cap_(nullptr, _VSTD::move(__x.__alloc())) 1207{ 1208 _VSTD::__debug_db_insert_c(this); 1209#if _LIBCPP_DEBUG_LEVEL == 2 1210 __get_db()->swap(this, _VSTD::addressof(__x)); 1211#endif 1212 this->__begin_ = __x.__begin_; 1213 this->__end_ = __x.__end_; 1214 this->__end_cap() = __x.__end_cap(); 1215 __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr; 1216} 1217 1218template <class _Tp, class _Allocator> 1219inline _LIBCPP_INLINE_VISIBILITY 1220vector<_Tp, _Allocator>::vector(vector&& __x, const __identity_t<allocator_type>& __a) 1221 : __end_cap_(nullptr, __a) 1222{ 1223 _VSTD::__debug_db_insert_c(this); 1224 if (__a == __x.__alloc()) 1225 { 1226 this->__begin_ = __x.__begin_; 1227 this->__end_ = __x.__end_; 1228 this->__end_cap() = __x.__end_cap(); 1229 __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr; 1230#if _LIBCPP_DEBUG_LEVEL == 2 1231 __get_db()->swap(this, _VSTD::addressof(__x)); 1232#endif 1233 } 1234 else 1235 { 1236 typedef move_iterator<iterator> _Ip; 1237 assign(_Ip(__x.begin()), _Ip(__x.end())); 1238 } 1239} 1240 1241template <class _Tp, class _Allocator> 1242inline _LIBCPP_INLINE_VISIBILITY 1243vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il) 1244{ 1245 _VSTD::__debug_db_insert_c(this); 1246 if (__il.size() > 0) 1247 { 1248 __vallocate(__il.size()); 1249 __construct_at_end(__il.begin(), __il.end(), __il.size()); 1250 } 1251} 1252 1253template <class _Tp, class _Allocator> 1254inline _LIBCPP_INLINE_VISIBILITY 1255vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a) 1256 : __end_cap_(nullptr, __a) 1257{ 1258 _VSTD::__debug_db_insert_c(this); 1259 if (__il.size() > 0) 1260 { 1261 __vallocate(__il.size()); 1262 __construct_at_end(__il.begin(), __il.end(), __il.size()); 1263 } 1264} 1265 1266template <class _Tp, class _Allocator> 1267inline _LIBCPP_INLINE_VISIBILITY 1268vector<_Tp, _Allocator>& 1269vector<_Tp, _Allocator>::operator=(vector&& __x) 1270 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) 1271{ 1272 __move_assign(__x, integral_constant<bool, 1273 __alloc_traits::propagate_on_container_move_assignment::value>()); 1274 return *this; 1275} 1276 1277template <class _Tp, class _Allocator> 1278void 1279vector<_Tp, _Allocator>::__move_assign(vector& __c, false_type) 1280 _NOEXCEPT_(__alloc_traits::is_always_equal::value) 1281{ 1282 if (__alloc() != __c.__alloc()) 1283 { 1284 typedef move_iterator<iterator> _Ip; 1285 assign(_Ip(__c.begin()), _Ip(__c.end())); 1286 } 1287 else 1288 __move_assign(__c, true_type()); 1289} 1290 1291template <class _Tp, class _Allocator> 1292void 1293vector<_Tp, _Allocator>::__move_assign(vector& __c, true_type) 1294 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) 1295{ 1296 __vdeallocate(); 1297 __move_assign_alloc(__c); // this can throw 1298 this->__begin_ = __c.__begin_; 1299 this->__end_ = __c.__end_; 1300 this->__end_cap() = __c.__end_cap(); 1301 __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr; 1302#if _LIBCPP_DEBUG_LEVEL == 2 1303 __get_db()->swap(this, _VSTD::addressof(__c)); 1304#endif 1305} 1306 1307#endif // !_LIBCPP_CXX03_LANG 1308 1309template <class _Tp, class _Allocator> 1310inline _LIBCPP_INLINE_VISIBILITY 1311vector<_Tp, _Allocator>& 1312vector<_Tp, _Allocator>::operator=(const vector& __x) 1313{ 1314 if (this != _VSTD::addressof(__x)) 1315 { 1316 __copy_assign_alloc(__x); 1317 assign(__x.__begin_, __x.__end_); 1318 } 1319 return *this; 1320} 1321 1322template <class _Tp, class _Allocator> 1323template <class _InputIterator> 1324typename enable_if 1325< 1326 __is_cpp17_input_iterator <_InputIterator>::value && 1327 !__is_cpp17_forward_iterator<_InputIterator>::value && 1328 is_constructible< 1329 _Tp, 1330 typename iterator_traits<_InputIterator>::reference>::value, 1331 void 1332>::type 1333vector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last) 1334{ 1335 clear(); 1336 for (; __first != __last; ++__first) 1337 __emplace_back(*__first); 1338} 1339 1340template <class _Tp, class _Allocator> 1341template <class _ForwardIterator> 1342typename enable_if 1343< 1344 __is_cpp17_forward_iterator<_ForwardIterator>::value && 1345 is_constructible< 1346 _Tp, 1347 typename iterator_traits<_ForwardIterator>::reference>::value, 1348 void 1349>::type 1350vector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last) 1351{ 1352 size_type __new_size = static_cast<size_type>(_VSTD::distance(__first, __last)); 1353 if (__new_size <= capacity()) 1354 { 1355 _ForwardIterator __mid = __last; 1356 bool __growing = false; 1357 if (__new_size > size()) 1358 { 1359 __growing = true; 1360 __mid = __first; 1361 _VSTD::advance(__mid, size()); 1362 } 1363 pointer __m = _VSTD::copy(__first, __mid, this->__begin_); 1364 if (__growing) 1365 __construct_at_end(__mid, __last, __new_size - size()); 1366 else 1367 this->__destruct_at_end(__m); 1368 } 1369 else 1370 { 1371 __vdeallocate(); 1372 __vallocate(__recommend(__new_size)); 1373 __construct_at_end(__first, __last, __new_size); 1374 } 1375 __invalidate_all_iterators(); 1376} 1377 1378template <class _Tp, class _Allocator> 1379void 1380vector<_Tp, _Allocator>::assign(size_type __n, const_reference __u) 1381{ 1382 if (__n <= capacity()) 1383 { 1384 size_type __s = size(); 1385 _VSTD::fill_n(this->__begin_, _VSTD::min(__n, __s), __u); 1386 if (__n > __s) 1387 __construct_at_end(__n - __s, __u); 1388 else 1389 this->__destruct_at_end(this->__begin_ + __n); 1390 } 1391 else 1392 { 1393 __vdeallocate(); 1394 __vallocate(__recommend(static_cast<size_type>(__n))); 1395 __construct_at_end(__n, __u); 1396 } 1397 __invalidate_all_iterators(); 1398} 1399 1400template <class _Tp, class _Allocator> 1401inline _LIBCPP_INLINE_VISIBILITY 1402typename vector<_Tp, _Allocator>::iterator 1403vector<_Tp, _Allocator>::__make_iter(pointer __p) _NOEXCEPT 1404{ 1405#if _LIBCPP_DEBUG_LEVEL == 2 1406 return iterator(this, __p); 1407#else 1408 return iterator(__p); 1409#endif 1410} 1411 1412template <class _Tp, class _Allocator> 1413inline _LIBCPP_INLINE_VISIBILITY 1414typename vector<_Tp, _Allocator>::const_iterator 1415vector<_Tp, _Allocator>::__make_iter(const_pointer __p) const _NOEXCEPT 1416{ 1417#if _LIBCPP_DEBUG_LEVEL == 2 1418 return const_iterator(this, __p); 1419#else 1420 return const_iterator(__p); 1421#endif 1422} 1423 1424template <class _Tp, class _Allocator> 1425inline _LIBCPP_INLINE_VISIBILITY 1426typename vector<_Tp, _Allocator>::iterator 1427vector<_Tp, _Allocator>::begin() _NOEXCEPT 1428{ 1429 return __make_iter(this->__begin_); 1430} 1431 1432template <class _Tp, class _Allocator> 1433inline _LIBCPP_INLINE_VISIBILITY 1434typename vector<_Tp, _Allocator>::const_iterator 1435vector<_Tp, _Allocator>::begin() const _NOEXCEPT 1436{ 1437 return __make_iter(this->__begin_); 1438} 1439 1440template <class _Tp, class _Allocator> 1441inline _LIBCPP_INLINE_VISIBILITY 1442typename vector<_Tp, _Allocator>::iterator 1443vector<_Tp, _Allocator>::end() _NOEXCEPT 1444{ 1445 return __make_iter(this->__end_); 1446} 1447 1448template <class _Tp, class _Allocator> 1449inline _LIBCPP_INLINE_VISIBILITY 1450typename vector<_Tp, _Allocator>::const_iterator 1451vector<_Tp, _Allocator>::end() const _NOEXCEPT 1452{ 1453 return __make_iter(this->__end_); 1454} 1455 1456template <class _Tp, class _Allocator> 1457inline _LIBCPP_INLINE_VISIBILITY 1458typename vector<_Tp, _Allocator>::reference 1459vector<_Tp, _Allocator>::operator[](size_type __n) _NOEXCEPT 1460{ 1461 _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds"); 1462 return this->__begin_[__n]; 1463} 1464 1465template <class _Tp, class _Allocator> 1466inline _LIBCPP_INLINE_VISIBILITY 1467typename vector<_Tp, _Allocator>::const_reference 1468vector<_Tp, _Allocator>::operator[](size_type __n) const _NOEXCEPT 1469{ 1470 _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds"); 1471 return this->__begin_[__n]; 1472} 1473 1474template <class _Tp, class _Allocator> 1475typename vector<_Tp, _Allocator>::reference 1476vector<_Tp, _Allocator>::at(size_type __n) 1477{ 1478 if (__n >= size()) 1479 this->__throw_out_of_range(); 1480 return this->__begin_[__n]; 1481} 1482 1483template <class _Tp, class _Allocator> 1484typename vector<_Tp, _Allocator>::const_reference 1485vector<_Tp, _Allocator>::at(size_type __n) const 1486{ 1487 if (__n >= size()) 1488 this->__throw_out_of_range(); 1489 return this->__begin_[__n]; 1490} 1491 1492template <class _Tp, class _Allocator> 1493void 1494vector<_Tp, _Allocator>::reserve(size_type __n) 1495{ 1496 if (__n > capacity()) 1497 { 1498 if (__n > max_size()) 1499 this->__throw_length_error(); 1500 allocator_type& __a = this->__alloc(); 1501 __split_buffer<value_type, allocator_type&> __v(__n, size(), __a); 1502 __swap_out_circular_buffer(__v); 1503 } 1504} 1505 1506template <class _Tp, class _Allocator> 1507void 1508vector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT 1509{ 1510 if (capacity() > size()) 1511 { 1512#ifndef _LIBCPP_NO_EXCEPTIONS 1513 try 1514 { 1515#endif // _LIBCPP_NO_EXCEPTIONS 1516 allocator_type& __a = this->__alloc(); 1517 __split_buffer<value_type, allocator_type&> __v(size(), size(), __a); 1518 __swap_out_circular_buffer(__v); 1519#ifndef _LIBCPP_NO_EXCEPTIONS 1520 } 1521 catch (...) 1522 { 1523 } 1524#endif // _LIBCPP_NO_EXCEPTIONS 1525 } 1526} 1527 1528template <class _Tp, class _Allocator> 1529template <class _Up> 1530void 1531#ifndef _LIBCPP_CXX03_LANG 1532vector<_Tp, _Allocator>::__push_back_slow_path(_Up&& __x) 1533#else 1534vector<_Tp, _Allocator>::__push_back_slow_path(_Up& __x) 1535#endif 1536{ 1537 allocator_type& __a = this->__alloc(); 1538 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a); 1539 // __v.push_back(_VSTD::forward<_Up>(__x)); 1540 __alloc_traits::construct(__a, _VSTD::__to_address(__v.__end_), _VSTD::forward<_Up>(__x)); 1541 __v.__end_++; 1542 __swap_out_circular_buffer(__v); 1543} 1544 1545template <class _Tp, class _Allocator> 1546inline _LIBCPP_INLINE_VISIBILITY 1547void 1548vector<_Tp, _Allocator>::push_back(const_reference __x) 1549{ 1550 if (this->__end_ != this->__end_cap()) 1551 { 1552 __construct_one_at_end(__x); 1553 } 1554 else 1555 __push_back_slow_path(__x); 1556} 1557 1558#ifndef _LIBCPP_CXX03_LANG 1559 1560template <class _Tp, class _Allocator> 1561inline _LIBCPP_INLINE_VISIBILITY 1562void 1563vector<_Tp, _Allocator>::push_back(value_type&& __x) 1564{ 1565 if (this->__end_ < this->__end_cap()) 1566 { 1567 __construct_one_at_end(_VSTD::move(__x)); 1568 } 1569 else 1570 __push_back_slow_path(_VSTD::move(__x)); 1571} 1572 1573template <class _Tp, class _Allocator> 1574template <class... _Args> 1575void 1576vector<_Tp, _Allocator>::__emplace_back_slow_path(_Args&&... __args) 1577{ 1578 allocator_type& __a = this->__alloc(); 1579 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a); 1580// __v.emplace_back(_VSTD::forward<_Args>(__args)...); 1581 __alloc_traits::construct(__a, _VSTD::__to_address(__v.__end_), _VSTD::forward<_Args>(__args)...); 1582 __v.__end_++; 1583 __swap_out_circular_buffer(__v); 1584} 1585 1586template <class _Tp, class _Allocator> 1587template <class... _Args> 1588inline 1589#if _LIBCPP_STD_VER > 14 1590typename vector<_Tp, _Allocator>::reference 1591#else 1592void 1593#endif 1594vector<_Tp, _Allocator>::emplace_back(_Args&&... __args) 1595{ 1596 if (this->__end_ < this->__end_cap()) 1597 { 1598 __construct_one_at_end(_VSTD::forward<_Args>(__args)...); 1599 } 1600 else 1601 __emplace_back_slow_path(_VSTD::forward<_Args>(__args)...); 1602#if _LIBCPP_STD_VER > 14 1603 return this->back(); 1604#endif 1605} 1606 1607#endif // !_LIBCPP_CXX03_LANG 1608 1609template <class _Tp, class _Allocator> 1610inline 1611void 1612vector<_Tp, _Allocator>::pop_back() 1613{ 1614 _LIBCPP_ASSERT(!empty(), "vector::pop_back called on an empty vector"); 1615 this->__destruct_at_end(this->__end_ - 1); 1616} 1617 1618template <class _Tp, class _Allocator> 1619inline _LIBCPP_INLINE_VISIBILITY 1620typename vector<_Tp, _Allocator>::iterator 1621vector<_Tp, _Allocator>::erase(const_iterator __position) 1622{ 1623 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this, 1624 "vector::erase(iterator) called with an iterator not referring to this vector"); 1625 _LIBCPP_ASSERT(__position != end(), 1626 "vector::erase(iterator) called with a non-dereferenceable iterator"); 1627 difference_type __ps = __position - cbegin(); 1628 pointer __p = this->__begin_ + __ps; 1629 this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p)); 1630 this->__invalidate_iterators_past(__p-1); 1631 iterator __r = __make_iter(__p); 1632 return __r; 1633} 1634 1635template <class _Tp, class _Allocator> 1636typename vector<_Tp, _Allocator>::iterator 1637vector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last) 1638{ 1639 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__first)) == this, 1640 "vector::erase(iterator, iterator) called with an iterator not referring to this vector"); 1641 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__last)) == this, 1642 "vector::erase(iterator, iterator) called with an iterator not referring to this vector"); 1643 1644 _LIBCPP_ASSERT(__first <= __last, "vector::erase(first, last) called with invalid range"); 1645 pointer __p = this->__begin_ + (__first - begin()); 1646 if (__first != __last) { 1647 this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p)); 1648 this->__invalidate_iterators_past(__p - 1); 1649 } 1650 iterator __r = __make_iter(__p); 1651 return __r; 1652} 1653 1654template <class _Tp, class _Allocator> 1655void 1656vector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to) 1657{ 1658 pointer __old_last = this->__end_; 1659 difference_type __n = __old_last - __to; 1660 { 1661 pointer __i = __from_s + __n; 1662 _ConstructTransaction __tx(*this, __from_e - __i); 1663 for (pointer __pos = __tx.__pos_; __i < __from_e; 1664 ++__i, (void) ++__pos, __tx.__pos_ = __pos) { 1665 __alloc_traits::construct(this->__alloc(), 1666 _VSTD::__to_address(__pos), 1667 _VSTD::move(*__i)); 1668 } 1669 } 1670 _VSTD::move_backward(__from_s, __from_s + __n, __old_last); 1671} 1672 1673template <class _Tp, class _Allocator> 1674typename vector<_Tp, _Allocator>::iterator 1675vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x) 1676{ 1677 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this, 1678 "vector::insert(iterator, x) called with an iterator not referring to this vector"); 1679 pointer __p = this->__begin_ + (__position - begin()); 1680 if (this->__end_ < this->__end_cap()) 1681 { 1682 if (__p == this->__end_) 1683 { 1684 __construct_one_at_end(__x); 1685 } 1686 else 1687 { 1688 __move_range(__p, this->__end_, __p + 1); 1689 const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x); 1690 if (__p <= __xr && __xr < this->__end_) 1691 ++__xr; 1692 *__p = *__xr; 1693 } 1694 } 1695 else 1696 { 1697 allocator_type& __a = this->__alloc(); 1698 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a); 1699 __v.push_back(__x); 1700 __p = __swap_out_circular_buffer(__v, __p); 1701 } 1702 return __make_iter(__p); 1703} 1704 1705#ifndef _LIBCPP_CXX03_LANG 1706 1707template <class _Tp, class _Allocator> 1708typename vector<_Tp, _Allocator>::iterator 1709vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x) 1710{ 1711 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this, 1712 "vector::insert(iterator, x) called with an iterator not referring to this vector"); 1713 pointer __p = this->__begin_ + (__position - begin()); 1714 if (this->__end_ < this->__end_cap()) 1715 { 1716 if (__p == this->__end_) 1717 { 1718 __construct_one_at_end(_VSTD::move(__x)); 1719 } 1720 else 1721 { 1722 __move_range(__p, this->__end_, __p + 1); 1723 *__p = _VSTD::move(__x); 1724 } 1725 } 1726 else 1727 { 1728 allocator_type& __a = this->__alloc(); 1729 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a); 1730 __v.push_back(_VSTD::move(__x)); 1731 __p = __swap_out_circular_buffer(__v, __p); 1732 } 1733 return __make_iter(__p); 1734} 1735 1736template <class _Tp, class _Allocator> 1737template <class... _Args> 1738typename vector<_Tp, _Allocator>::iterator 1739vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args) 1740{ 1741 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this, 1742 "vector::emplace(iterator, x) called with an iterator not referring to this vector"); 1743 pointer __p = this->__begin_ + (__position - begin()); 1744 if (this->__end_ < this->__end_cap()) 1745 { 1746 if (__p == this->__end_) 1747 { 1748 __construct_one_at_end(_VSTD::forward<_Args>(__args)...); 1749 } 1750 else 1751 { 1752 __temp_value<value_type, _Allocator> __tmp(this->__alloc(), _VSTD::forward<_Args>(__args)...); 1753 __move_range(__p, this->__end_, __p + 1); 1754 *__p = _VSTD::move(__tmp.get()); 1755 } 1756 } 1757 else 1758 { 1759 allocator_type& __a = this->__alloc(); 1760 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a); 1761 __v.emplace_back(_VSTD::forward<_Args>(__args)...); 1762 __p = __swap_out_circular_buffer(__v, __p); 1763 } 1764 return __make_iter(__p); 1765} 1766 1767#endif // !_LIBCPP_CXX03_LANG 1768 1769template <class _Tp, class _Allocator> 1770typename vector<_Tp, _Allocator>::iterator 1771vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x) 1772{ 1773 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this, 1774 "vector::insert(iterator, n, x) called with an iterator not referring to this vector"); 1775 pointer __p = this->__begin_ + (__position - begin()); 1776 if (__n > 0) 1777 { 1778 if (__n <= static_cast<size_type>(this->__end_cap() - this->__end_)) 1779 { 1780 size_type __old_n = __n; 1781 pointer __old_last = this->__end_; 1782 if (__n > static_cast<size_type>(this->__end_ - __p)) 1783 { 1784 size_type __cx = __n - (this->__end_ - __p); 1785 __construct_at_end(__cx, __x); 1786 __n -= __cx; 1787 } 1788 if (__n > 0) 1789 { 1790 __move_range(__p, __old_last, __p + __old_n); 1791 const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x); 1792 if (__p <= __xr && __xr < this->__end_) 1793 __xr += __old_n; 1794 _VSTD::fill_n(__p, __n, *__xr); 1795 } 1796 } 1797 else 1798 { 1799 allocator_type& __a = this->__alloc(); 1800 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a); 1801 __v.__construct_at_end(__n, __x); 1802 __p = __swap_out_circular_buffer(__v, __p); 1803 } 1804 } 1805 return __make_iter(__p); 1806} 1807 1808template <class _Tp, class _Allocator> 1809template <class _InputIterator> 1810typename enable_if 1811< 1812 __is_cpp17_input_iterator <_InputIterator>::value && 1813 !__is_cpp17_forward_iterator<_InputIterator>::value && 1814 is_constructible< 1815 _Tp, 1816 typename iterator_traits<_InputIterator>::reference>::value, 1817 typename vector<_Tp, _Allocator>::iterator 1818>::type 1819vector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last) 1820{ 1821 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this, 1822 "vector::insert(iterator, range) called with an iterator not referring to this vector"); 1823 difference_type __off = __position - begin(); 1824 pointer __p = this->__begin_ + __off; 1825 allocator_type& __a = this->__alloc(); 1826 pointer __old_last = this->__end_; 1827 for (; this->__end_ != this->__end_cap() && __first != __last; ++__first) 1828 { 1829 __construct_one_at_end(*__first); 1830 } 1831 __split_buffer<value_type, allocator_type&> __v(__a); 1832 if (__first != __last) 1833 { 1834#ifndef _LIBCPP_NO_EXCEPTIONS 1835 try 1836 { 1837#endif // _LIBCPP_NO_EXCEPTIONS 1838 __v.__construct_at_end(__first, __last); 1839 difference_type __old_size = __old_last - this->__begin_; 1840 difference_type __old_p = __p - this->__begin_; 1841 reserve(__recommend(size() + __v.size())); 1842 __p = this->__begin_ + __old_p; 1843 __old_last = this->__begin_ + __old_size; 1844#ifndef _LIBCPP_NO_EXCEPTIONS 1845 } 1846 catch (...) 1847 { 1848 erase(__make_iter(__old_last), end()); 1849 throw; 1850 } 1851#endif // _LIBCPP_NO_EXCEPTIONS 1852 } 1853 __p = _VSTD::rotate(__p, __old_last, this->__end_); 1854 insert(__make_iter(__p), _VSTD::make_move_iterator(__v.begin()), 1855 _VSTD::make_move_iterator(__v.end())); 1856 return begin() + __off; 1857} 1858 1859template <class _Tp, class _Allocator> 1860template <class _ForwardIterator> 1861typename enable_if 1862< 1863 __is_cpp17_forward_iterator<_ForwardIterator>::value && 1864 is_constructible< 1865 _Tp, 1866 typename iterator_traits<_ForwardIterator>::reference>::value, 1867 typename vector<_Tp, _Allocator>::iterator 1868>::type 1869vector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last) 1870{ 1871 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this, 1872 "vector::insert(iterator, range) called with an iterator not referring to this vector"); 1873 pointer __p = this->__begin_ + (__position - begin()); 1874 difference_type __n = _VSTD::distance(__first, __last); 1875 if (__n > 0) 1876 { 1877 if (__n <= this->__end_cap() - this->__end_) 1878 { 1879 size_type __old_n = __n; 1880 pointer __old_last = this->__end_; 1881 _ForwardIterator __m = __last; 1882 difference_type __dx = this->__end_ - __p; 1883 if (__n > __dx) 1884 { 1885 __m = __first; 1886 difference_type __diff = this->__end_ - __p; 1887 _VSTD::advance(__m, __diff); 1888 __construct_at_end(__m, __last, __n - __diff); 1889 __n = __dx; 1890 } 1891 if (__n > 0) 1892 { 1893 __move_range(__p, __old_last, __p + __old_n); 1894 _VSTD::copy(__first, __m, __p); 1895 } 1896 } 1897 else 1898 { 1899 allocator_type& __a = this->__alloc(); 1900 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a); 1901 __v.__construct_at_end(__first, __last); 1902 __p = __swap_out_circular_buffer(__v, __p); 1903 } 1904 } 1905 return __make_iter(__p); 1906} 1907 1908template <class _Tp, class _Allocator> 1909void 1910vector<_Tp, _Allocator>::resize(size_type __sz) 1911{ 1912 size_type __cs = size(); 1913 if (__cs < __sz) 1914 this->__append(__sz - __cs); 1915 else if (__cs > __sz) 1916 this->__destruct_at_end(this->__begin_ + __sz); 1917} 1918 1919template <class _Tp, class _Allocator> 1920void 1921vector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x) 1922{ 1923 size_type __cs = size(); 1924 if (__cs < __sz) 1925 this->__append(__sz - __cs, __x); 1926 else if (__cs > __sz) 1927 this->__destruct_at_end(this->__begin_ + __sz); 1928} 1929 1930template <class _Tp, class _Allocator> 1931void 1932vector<_Tp, _Allocator>::swap(vector& __x) 1933#if _LIBCPP_STD_VER >= 14 1934 _NOEXCEPT 1935#else 1936 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || 1937 __is_nothrow_swappable<allocator_type>::value) 1938#endif 1939{ 1940 _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value || 1941 this->__alloc() == __x.__alloc(), 1942 "vector::swap: Either propagate_on_container_swap must be true" 1943 " or the allocators must compare equal"); 1944 _VSTD::swap(this->__begin_, __x.__begin_); 1945 _VSTD::swap(this->__end_, __x.__end_); 1946 _VSTD::swap(this->__end_cap(), __x.__end_cap()); 1947 _VSTD::__swap_allocator(this->__alloc(), __x.__alloc(), 1948 integral_constant<bool,__alloc_traits::propagate_on_container_swap::value>()); 1949#if _LIBCPP_DEBUG_LEVEL == 2 1950 __get_db()->swap(this, _VSTD::addressof(__x)); 1951#endif 1952} 1953 1954template <class _Tp, class _Allocator> 1955bool 1956vector<_Tp, _Allocator>::__invariants() const 1957{ 1958 if (this->__begin_ == nullptr) 1959 { 1960 if (this->__end_ != nullptr || this->__end_cap() != nullptr) 1961 return false; 1962 } 1963 else 1964 { 1965 if (this->__begin_ > this->__end_) 1966 return false; 1967 if (this->__begin_ == this->__end_cap()) 1968 return false; 1969 if (this->__end_ > this->__end_cap()) 1970 return false; 1971 } 1972 return true; 1973} 1974 1975#if _LIBCPP_DEBUG_LEVEL == 2 1976 1977template <class _Tp, class _Allocator> 1978bool 1979vector<_Tp, _Allocator>::__dereferenceable(const const_iterator* __i) const 1980{ 1981 return this->__begin_ <= __i->base() && __i->base() < this->__end_; 1982} 1983 1984template <class _Tp, class _Allocator> 1985bool 1986vector<_Tp, _Allocator>::__decrementable(const const_iterator* __i) const 1987{ 1988 return this->__begin_ < __i->base() && __i->base() <= this->__end_; 1989} 1990 1991template <class _Tp, class _Allocator> 1992bool 1993vector<_Tp, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const 1994{ 1995 const_pointer __p = __i->base() + __n; 1996 return this->__begin_ <= __p && __p <= this->__end_; 1997} 1998 1999template <class _Tp, class _Allocator> 2000bool 2001vector<_Tp, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const 2002{ 2003 const_pointer __p = __i->base() + __n; 2004 return this->__begin_ <= __p && __p < this->__end_; 2005} 2006 2007#endif // _LIBCPP_DEBUG_LEVEL == 2 2008 2009template <class _Tp, class _Allocator> 2010inline _LIBCPP_INLINE_VISIBILITY 2011void 2012vector<_Tp, _Allocator>::__invalidate_all_iterators() 2013{ 2014#if _LIBCPP_DEBUG_LEVEL == 2 2015 __get_db()->__invalidate_all(this); 2016#endif 2017} 2018 2019 2020template <class _Tp, class _Allocator> 2021inline _LIBCPP_INLINE_VISIBILITY 2022void 2023vector<_Tp, _Allocator>::__invalidate_iterators_past(pointer __new_last) { 2024#if _LIBCPP_DEBUG_LEVEL == 2 2025 __c_node* __c = __get_db()->__find_c_and_lock(this); 2026 for (__i_node** __p = __c->end_; __p != __c->beg_; ) { 2027 --__p; 2028 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_); 2029 if (__i->base() > __new_last) { 2030 (*__p)->__c_ = nullptr; 2031 if (--__c->end_ != __p) 2032 _VSTD::memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); 2033 } 2034 } 2035 __get_db()->unlock(); 2036#else 2037 ((void)__new_last); 2038#endif 2039} 2040 2041// vector<bool> 2042 2043template <class _Allocator> class vector<bool, _Allocator>; 2044 2045template <class _Allocator> struct hash<vector<bool, _Allocator> >; 2046 2047template <class _Allocator> 2048struct __has_storage_type<vector<bool, _Allocator> > 2049{ 2050 static const bool value = true; 2051}; 2052 2053template <class _Allocator> 2054class _LIBCPP_TEMPLATE_VIS vector<bool, _Allocator> 2055{ 2056public: 2057 typedef vector __self; 2058 typedef bool value_type; 2059 typedef _Allocator allocator_type; 2060 typedef allocator_traits<allocator_type> __alloc_traits; 2061 typedef typename __alloc_traits::size_type size_type; 2062 typedef typename __alloc_traits::difference_type difference_type; 2063 typedef size_type __storage_type; 2064 typedef __bit_iterator<vector, false> pointer; 2065 typedef __bit_iterator<vector, true> const_pointer; 2066 typedef pointer iterator; 2067 typedef const_pointer const_iterator; 2068 typedef _VSTD::reverse_iterator<iterator> reverse_iterator; 2069 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; 2070 2071private: 2072 typedef typename __rebind_alloc_helper<__alloc_traits, __storage_type>::type __storage_allocator; 2073 typedef allocator_traits<__storage_allocator> __storage_traits; 2074 typedef typename __storage_traits::pointer __storage_pointer; 2075 typedef typename __storage_traits::const_pointer __const_storage_pointer; 2076 2077 __storage_pointer __begin_; 2078 size_type __size_; 2079 __compressed_pair<size_type, __storage_allocator> __cap_alloc_; 2080public: 2081 typedef __bit_reference<vector> reference; 2082 typedef __bit_const_reference<vector> const_reference; 2083private: 2084 _LIBCPP_INLINE_VISIBILITY 2085 size_type& __cap() _NOEXCEPT 2086 {return __cap_alloc_.first();} 2087 _LIBCPP_INLINE_VISIBILITY 2088 const size_type& __cap() const _NOEXCEPT 2089 {return __cap_alloc_.first();} 2090 _LIBCPP_INLINE_VISIBILITY 2091 __storage_allocator& __alloc() _NOEXCEPT 2092 {return __cap_alloc_.second();} 2093 _LIBCPP_INLINE_VISIBILITY 2094 const __storage_allocator& __alloc() const _NOEXCEPT 2095 {return __cap_alloc_.second();} 2096 2097 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); 2098 2099 _LIBCPP_INLINE_VISIBILITY 2100 static size_type __internal_cap_to_external(size_type __n) _NOEXCEPT 2101 {return __n * __bits_per_word;} 2102 _LIBCPP_INLINE_VISIBILITY 2103 static size_type __external_cap_to_internal(size_type __n) _NOEXCEPT 2104 {return (__n - 1) / __bits_per_word + 1;} 2105 2106public: 2107 _LIBCPP_INLINE_VISIBILITY 2108 vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value); 2109 2110 _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a) 2111#if _LIBCPP_STD_VER <= 14 2112 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value); 2113#else 2114 _NOEXCEPT; 2115#endif 2116 ~vector(); 2117 explicit vector(size_type __n); 2118#if _LIBCPP_STD_VER > 11 2119 explicit vector(size_type __n, const allocator_type& __a); 2120#endif 2121 vector(size_type __n, const value_type& __v); 2122 vector(size_type __n, const value_type& __v, const allocator_type& __a); 2123 template <class _InputIterator> 2124 vector(_InputIterator __first, _InputIterator __last, 2125 typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value && 2126 !__is_cpp17_forward_iterator<_InputIterator>::value>::type* = 0); 2127 template <class _InputIterator> 2128 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, 2129 typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value && 2130 !__is_cpp17_forward_iterator<_InputIterator>::value>::type* = 0); 2131 template <class _ForwardIterator> 2132 vector(_ForwardIterator __first, _ForwardIterator __last, 2133 typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type* = 0); 2134 template <class _ForwardIterator> 2135 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, 2136 typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type* = 0); 2137 2138 vector(const vector& __v); 2139 vector(const vector& __v, const allocator_type& __a); 2140 vector& operator=(const vector& __v); 2141 2142#ifndef _LIBCPP_CXX03_LANG 2143 vector(initializer_list<value_type> __il); 2144 vector(initializer_list<value_type> __il, const allocator_type& __a); 2145 2146 _LIBCPP_INLINE_VISIBILITY 2147 vector(vector&& __v) 2148#if _LIBCPP_STD_VER > 14 2149 _NOEXCEPT; 2150#else 2151 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value); 2152#endif 2153 vector(vector&& __v, const __identity_t<allocator_type>& __a); 2154 _LIBCPP_INLINE_VISIBILITY 2155 vector& operator=(vector&& __v) 2156 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)); 2157 2158 _LIBCPP_INLINE_VISIBILITY 2159 vector& operator=(initializer_list<value_type> __il) 2160 {assign(__il.begin(), __il.end()); return *this;} 2161 2162#endif // !_LIBCPP_CXX03_LANG 2163 2164 template <class _InputIterator> 2165 typename enable_if 2166 < 2167 __is_cpp17_input_iterator<_InputIterator>::value && 2168 !__is_cpp17_forward_iterator<_InputIterator>::value, 2169 void 2170 >::type 2171 assign(_InputIterator __first, _InputIterator __last); 2172 template <class _ForwardIterator> 2173 typename enable_if 2174 < 2175 __is_cpp17_forward_iterator<_ForwardIterator>::value, 2176 void 2177 >::type 2178 assign(_ForwardIterator __first, _ForwardIterator __last); 2179 2180 void assign(size_type __n, const value_type& __x); 2181 2182#ifndef _LIBCPP_CXX03_LANG 2183 _LIBCPP_INLINE_VISIBILITY 2184 void assign(initializer_list<value_type> __il) 2185 {assign(__il.begin(), __il.end());} 2186#endif 2187 2188 _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT 2189 {return allocator_type(this->__alloc());} 2190 2191 size_type max_size() const _NOEXCEPT; 2192 _LIBCPP_INLINE_VISIBILITY 2193 size_type capacity() const _NOEXCEPT 2194 {return __internal_cap_to_external(__cap());} 2195 _LIBCPP_INLINE_VISIBILITY 2196 size_type size() const _NOEXCEPT 2197 {return __size_;} 2198 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 2199 bool empty() const _NOEXCEPT 2200 {return __size_ == 0;} 2201 void reserve(size_type __n); 2202 void shrink_to_fit() _NOEXCEPT; 2203 2204 _LIBCPP_INLINE_VISIBILITY 2205 iterator begin() _NOEXCEPT 2206 {return __make_iter(0);} 2207 _LIBCPP_INLINE_VISIBILITY 2208 const_iterator begin() const _NOEXCEPT 2209 {return __make_iter(0);} 2210 _LIBCPP_INLINE_VISIBILITY 2211 iterator end() _NOEXCEPT 2212 {return __make_iter(__size_);} 2213 _LIBCPP_INLINE_VISIBILITY 2214 const_iterator end() const _NOEXCEPT 2215 {return __make_iter(__size_);} 2216 2217 _LIBCPP_INLINE_VISIBILITY 2218 reverse_iterator rbegin() _NOEXCEPT 2219 {return reverse_iterator(end());} 2220 _LIBCPP_INLINE_VISIBILITY 2221 const_reverse_iterator rbegin() const _NOEXCEPT 2222 {return const_reverse_iterator(end());} 2223 _LIBCPP_INLINE_VISIBILITY 2224 reverse_iterator rend() _NOEXCEPT 2225 {return reverse_iterator(begin());} 2226 _LIBCPP_INLINE_VISIBILITY 2227 const_reverse_iterator rend() const _NOEXCEPT 2228 {return const_reverse_iterator(begin());} 2229 2230 _LIBCPP_INLINE_VISIBILITY 2231 const_iterator cbegin() const _NOEXCEPT 2232 {return __make_iter(0);} 2233 _LIBCPP_INLINE_VISIBILITY 2234 const_iterator cend() const _NOEXCEPT 2235 {return __make_iter(__size_);} 2236 _LIBCPP_INLINE_VISIBILITY 2237 const_reverse_iterator crbegin() const _NOEXCEPT 2238 {return rbegin();} 2239 _LIBCPP_INLINE_VISIBILITY 2240 const_reverse_iterator crend() const _NOEXCEPT 2241 {return rend();} 2242 2243 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) {return __make_ref(__n);} 2244 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const {return __make_ref(__n);} 2245 reference at(size_type __n); 2246 const_reference at(size_type __n) const; 2247 2248 _LIBCPP_INLINE_VISIBILITY reference front() {return __make_ref(0);} 2249 _LIBCPP_INLINE_VISIBILITY const_reference front() const {return __make_ref(0);} 2250 _LIBCPP_INLINE_VISIBILITY reference back() {return __make_ref(__size_ - 1);} 2251 _LIBCPP_INLINE_VISIBILITY const_reference back() const {return __make_ref(__size_ - 1);} 2252 2253 void push_back(const value_type& __x); 2254#if _LIBCPP_STD_VER > 11 2255 template <class... _Args> 2256#if _LIBCPP_STD_VER > 14 2257 _LIBCPP_INLINE_VISIBILITY reference emplace_back(_Args&&... __args) 2258#else 2259 _LIBCPP_INLINE_VISIBILITY void emplace_back(_Args&&... __args) 2260#endif 2261 { 2262 push_back ( value_type ( _VSTD::forward<_Args>(__args)... )); 2263#if _LIBCPP_STD_VER > 14 2264 return this->back(); 2265#endif 2266 } 2267#endif 2268 2269 _LIBCPP_INLINE_VISIBILITY void pop_back() {--__size_;} 2270 2271#if _LIBCPP_STD_VER > 11 2272 template <class... _Args> 2273 _LIBCPP_INLINE_VISIBILITY iterator emplace(const_iterator position, _Args&&... __args) 2274 { return insert ( position, value_type ( _VSTD::forward<_Args>(__args)... )); } 2275#endif 2276 2277 iterator insert(const_iterator __position, const value_type& __x); 2278 iterator insert(const_iterator __position, size_type __n, const value_type& __x); 2279 iterator insert(const_iterator __position, size_type __n, const_reference __x); 2280 template <class _InputIterator> 2281 typename enable_if 2282 < 2283 __is_cpp17_input_iterator <_InputIterator>::value && 2284 !__is_cpp17_forward_iterator<_InputIterator>::value, 2285 iterator 2286 >::type 2287 insert(const_iterator __position, _InputIterator __first, _InputIterator __last); 2288 template <class _ForwardIterator> 2289 typename enable_if 2290 < 2291 __is_cpp17_forward_iterator<_ForwardIterator>::value, 2292 iterator 2293 >::type 2294 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last); 2295 2296#ifndef _LIBCPP_CXX03_LANG 2297 _LIBCPP_INLINE_VISIBILITY 2298 iterator insert(const_iterator __position, initializer_list<value_type> __il) 2299 {return insert(__position, __il.begin(), __il.end());} 2300#endif 2301 2302 _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position); 2303 iterator erase(const_iterator __first, const_iterator __last); 2304 2305 _LIBCPP_INLINE_VISIBILITY 2306 void clear() _NOEXCEPT {__size_ = 0;} 2307 2308 void swap(vector&) 2309#if _LIBCPP_STD_VER >= 14 2310 _NOEXCEPT; 2311#else 2312 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || 2313 __is_nothrow_swappable<allocator_type>::value); 2314#endif 2315 static void swap(reference __x, reference __y) _NOEXCEPT { _VSTD::swap(__x, __y); } 2316 2317 void resize(size_type __sz, value_type __x = false); 2318 void flip() _NOEXCEPT; 2319 2320 bool __invariants() const; 2321 2322private: 2323 _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI 2324 void __throw_length_error() const { 2325 _VSTD::__throw_length_error("vector"); 2326 } 2327 2328 _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI 2329 void __throw_out_of_range() const { 2330 _VSTD::__throw_out_of_range("vector"); 2331 } 2332 2333 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators(); 2334 void __vallocate(size_type __n); 2335 void __vdeallocate() _NOEXCEPT; 2336 _LIBCPP_INLINE_VISIBILITY 2337 static size_type __align_it(size_type __new_size) _NOEXCEPT 2338 {return (__new_size + (__bits_per_word-1)) & ~((size_type)__bits_per_word-1);} 2339 _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const; 2340 _LIBCPP_INLINE_VISIBILITY void __construct_at_end(size_type __n, bool __x); 2341 template <class _ForwardIterator> 2342 typename enable_if 2343 < 2344 __is_cpp17_forward_iterator<_ForwardIterator>::value, 2345 void 2346 >::type 2347 __construct_at_end(_ForwardIterator __first, _ForwardIterator __last); 2348 void __append(size_type __n, const_reference __x); 2349 _LIBCPP_INLINE_VISIBILITY 2350 reference __make_ref(size_type __pos) _NOEXCEPT 2351 {return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);} 2352 _LIBCPP_INLINE_VISIBILITY 2353 const_reference __make_ref(size_type __pos) const _NOEXCEPT 2354 {return const_reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);} 2355 _LIBCPP_INLINE_VISIBILITY 2356 iterator __make_iter(size_type __pos) _NOEXCEPT 2357 {return iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));} 2358 _LIBCPP_INLINE_VISIBILITY 2359 const_iterator __make_iter(size_type __pos) const _NOEXCEPT 2360 {return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));} 2361 _LIBCPP_INLINE_VISIBILITY 2362 iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT 2363 {return begin() + (__p - cbegin());} 2364 2365 _LIBCPP_INLINE_VISIBILITY 2366 void __copy_assign_alloc(const vector& __v) 2367 {__copy_assign_alloc(__v, integral_constant<bool, 2368 __storage_traits::propagate_on_container_copy_assignment::value>());} 2369 _LIBCPP_INLINE_VISIBILITY 2370 void __copy_assign_alloc(const vector& __c, true_type) 2371 { 2372 if (__alloc() != __c.__alloc()) 2373 __vdeallocate(); 2374 __alloc() = __c.__alloc(); 2375 } 2376 2377 _LIBCPP_INLINE_VISIBILITY 2378 void __copy_assign_alloc(const vector&, false_type) 2379 {} 2380 2381 void __move_assign(vector& __c, false_type); 2382 void __move_assign(vector& __c, true_type) 2383 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); 2384 _LIBCPP_INLINE_VISIBILITY 2385 void __move_assign_alloc(vector& __c) 2386 _NOEXCEPT_( 2387 !__storage_traits::propagate_on_container_move_assignment::value || 2388 is_nothrow_move_assignable<allocator_type>::value) 2389 {__move_assign_alloc(__c, integral_constant<bool, 2390 __storage_traits::propagate_on_container_move_assignment::value>());} 2391 _LIBCPP_INLINE_VISIBILITY 2392 void __move_assign_alloc(vector& __c, true_type) 2393 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) 2394 { 2395 __alloc() = _VSTD::move(__c.__alloc()); 2396 } 2397 2398 _LIBCPP_INLINE_VISIBILITY 2399 void __move_assign_alloc(vector&, false_type) 2400 _NOEXCEPT 2401 {} 2402 2403 size_t __hash_code() const _NOEXCEPT; 2404 2405 friend class __bit_reference<vector>; 2406 friend class __bit_const_reference<vector>; 2407 friend class __bit_iterator<vector, false>; 2408 friend class __bit_iterator<vector, true>; 2409 friend struct __bit_array<vector>; 2410 friend struct _LIBCPP_TEMPLATE_VIS hash<vector>; 2411}; 2412 2413template <class _Allocator> 2414inline _LIBCPP_INLINE_VISIBILITY 2415void 2416vector<bool, _Allocator>::__invalidate_all_iterators() 2417{ 2418} 2419 2420// Allocate space for __n objects 2421// throws length_error if __n > max_size() 2422// throws (probably bad_alloc) if memory run out 2423// Precondition: __begin_ == __end_ == __cap() == 0 2424// Precondition: __n > 0 2425// Postcondition: capacity() == __n 2426// Postcondition: size() == 0 2427template <class _Allocator> 2428void 2429vector<bool, _Allocator>::__vallocate(size_type __n) 2430{ 2431 if (__n > max_size()) 2432 this->__throw_length_error(); 2433 __n = __external_cap_to_internal(__n); 2434 this->__begin_ = __storage_traits::allocate(this->__alloc(), __n); 2435 this->__size_ = 0; 2436 this->__cap() = __n; 2437} 2438 2439template <class _Allocator> 2440void 2441vector<bool, _Allocator>::__vdeallocate() _NOEXCEPT 2442{ 2443 if (this->__begin_ != nullptr) 2444 { 2445 __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap()); 2446 __invalidate_all_iterators(); 2447 this->__begin_ = nullptr; 2448 this->__size_ = this->__cap() = 0; 2449 } 2450} 2451 2452template <class _Allocator> 2453typename vector<bool, _Allocator>::size_type 2454vector<bool, _Allocator>::max_size() const _NOEXCEPT 2455{ 2456 size_type __amax = __storage_traits::max_size(__alloc()); 2457 size_type __nmax = numeric_limits<size_type>::max() / 2; // end() >= begin(), always 2458 if (__nmax / __bits_per_word <= __amax) 2459 return __nmax; 2460 return __internal_cap_to_external(__amax); 2461} 2462 2463// Precondition: __new_size > capacity() 2464template <class _Allocator> 2465inline _LIBCPP_INLINE_VISIBILITY 2466typename vector<bool, _Allocator>::size_type 2467vector<bool, _Allocator>::__recommend(size_type __new_size) const 2468{ 2469 const size_type __ms = max_size(); 2470 if (__new_size > __ms) 2471 this->__throw_length_error(); 2472 const size_type __cap = capacity(); 2473 if (__cap >= __ms / 2) 2474 return __ms; 2475 return _VSTD::max(2 * __cap, __align_it(__new_size)); 2476} 2477 2478// Default constructs __n objects starting at __end_ 2479// Precondition: __n > 0 2480// Precondition: size() + __n <= capacity() 2481// Postcondition: size() == size() + __n 2482template <class _Allocator> 2483inline _LIBCPP_INLINE_VISIBILITY 2484void 2485vector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x) 2486{ 2487 size_type __old_size = this->__size_; 2488 this->__size_ += __n; 2489 if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word)) 2490 { 2491 if (this->__size_ <= __bits_per_word) 2492 this->__begin_[0] = __storage_type(0); 2493 else 2494 this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0); 2495 } 2496 _VSTD::fill_n(__make_iter(__old_size), __n, __x); 2497} 2498 2499template <class _Allocator> 2500template <class _ForwardIterator> 2501typename enable_if 2502< 2503 __is_cpp17_forward_iterator<_ForwardIterator>::value, 2504 void 2505>::type 2506vector<bool, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last) 2507{ 2508 size_type __old_size = this->__size_; 2509 this->__size_ += _VSTD::distance(__first, __last); 2510 if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word)) 2511 { 2512 if (this->__size_ <= __bits_per_word) 2513 this->__begin_[0] = __storage_type(0); 2514 else 2515 this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0); 2516 } 2517 _VSTD::copy(__first, __last, __make_iter(__old_size)); 2518} 2519 2520template <class _Allocator> 2521inline _LIBCPP_INLINE_VISIBILITY 2522vector<bool, _Allocator>::vector() 2523 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) 2524 : __begin_(nullptr), 2525 __size_(0), 2526 __cap_alloc_(0, __default_init_tag()) 2527{ 2528} 2529 2530template <class _Allocator> 2531inline _LIBCPP_INLINE_VISIBILITY 2532vector<bool, _Allocator>::vector(const allocator_type& __a) 2533#if _LIBCPP_STD_VER <= 14 2534 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value) 2535#else 2536 _NOEXCEPT 2537#endif 2538 : __begin_(nullptr), 2539 __size_(0), 2540 __cap_alloc_(0, static_cast<__storage_allocator>(__a)) 2541{ 2542} 2543 2544template <class _Allocator> 2545vector<bool, _Allocator>::vector(size_type __n) 2546 : __begin_(nullptr), 2547 __size_(0), 2548 __cap_alloc_(0, __default_init_tag()) 2549{ 2550 if (__n > 0) 2551 { 2552 __vallocate(__n); 2553 __construct_at_end(__n, false); 2554 } 2555} 2556 2557#if _LIBCPP_STD_VER > 11 2558template <class _Allocator> 2559vector<bool, _Allocator>::vector(size_type __n, const allocator_type& __a) 2560 : __begin_(nullptr), 2561 __size_(0), 2562 __cap_alloc_(0, static_cast<__storage_allocator>(__a)) 2563{ 2564 if (__n > 0) 2565 { 2566 __vallocate(__n); 2567 __construct_at_end(__n, false); 2568 } 2569} 2570#endif 2571 2572template <class _Allocator> 2573vector<bool, _Allocator>::vector(size_type __n, const value_type& __x) 2574 : __begin_(nullptr), 2575 __size_(0), 2576 __cap_alloc_(0, __default_init_tag()) 2577{ 2578 if (__n > 0) 2579 { 2580 __vallocate(__n); 2581 __construct_at_end(__n, __x); 2582 } 2583} 2584 2585template <class _Allocator> 2586vector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a) 2587 : __begin_(nullptr), 2588 __size_(0), 2589 __cap_alloc_(0, static_cast<__storage_allocator>(__a)) 2590{ 2591 if (__n > 0) 2592 { 2593 __vallocate(__n); 2594 __construct_at_end(__n, __x); 2595 } 2596} 2597 2598template <class _Allocator> 2599template <class _InputIterator> 2600vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, 2601 typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value && 2602 !__is_cpp17_forward_iterator<_InputIterator>::value>::type*) 2603 : __begin_(nullptr), 2604 __size_(0), 2605 __cap_alloc_(0, __default_init_tag()) 2606{ 2607#ifndef _LIBCPP_NO_EXCEPTIONS 2608 try 2609 { 2610#endif // _LIBCPP_NO_EXCEPTIONS 2611 for (; __first != __last; ++__first) 2612 push_back(*__first); 2613#ifndef _LIBCPP_NO_EXCEPTIONS 2614 } 2615 catch (...) 2616 { 2617 if (__begin_ != nullptr) 2618 __storage_traits::deallocate(__alloc(), __begin_, __cap()); 2619 __invalidate_all_iterators(); 2620 throw; 2621 } 2622#endif // _LIBCPP_NO_EXCEPTIONS 2623} 2624 2625template <class _Allocator> 2626template <class _InputIterator> 2627vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, 2628 typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value && 2629 !__is_cpp17_forward_iterator<_InputIterator>::value>::type*) 2630 : __begin_(nullptr), 2631 __size_(0), 2632 __cap_alloc_(0, static_cast<__storage_allocator>(__a)) 2633{ 2634#ifndef _LIBCPP_NO_EXCEPTIONS 2635 try 2636 { 2637#endif // _LIBCPP_NO_EXCEPTIONS 2638 for (; __first != __last; ++__first) 2639 push_back(*__first); 2640#ifndef _LIBCPP_NO_EXCEPTIONS 2641 } 2642 catch (...) 2643 { 2644 if (__begin_ != nullptr) 2645 __storage_traits::deallocate(__alloc(), __begin_, __cap()); 2646 __invalidate_all_iterators(); 2647 throw; 2648 } 2649#endif // _LIBCPP_NO_EXCEPTIONS 2650} 2651 2652template <class _Allocator> 2653template <class _ForwardIterator> 2654vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, 2655 typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type*) 2656 : __begin_(nullptr), 2657 __size_(0), 2658 __cap_alloc_(0, __default_init_tag()) 2659{ 2660 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); 2661 if (__n > 0) 2662 { 2663 __vallocate(__n); 2664 __construct_at_end(__first, __last); 2665 } 2666} 2667 2668template <class _Allocator> 2669template <class _ForwardIterator> 2670vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, 2671 typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type*) 2672 : __begin_(nullptr), 2673 __size_(0), 2674 __cap_alloc_(0, static_cast<__storage_allocator>(__a)) 2675{ 2676 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); 2677 if (__n > 0) 2678 { 2679 __vallocate(__n); 2680 __construct_at_end(__first, __last); 2681 } 2682} 2683 2684#ifndef _LIBCPP_CXX03_LANG 2685 2686template <class _Allocator> 2687vector<bool, _Allocator>::vector(initializer_list<value_type> __il) 2688 : __begin_(nullptr), 2689 __size_(0), 2690 __cap_alloc_(0, __default_init_tag()) 2691{ 2692 size_type __n = static_cast<size_type>(__il.size()); 2693 if (__n > 0) 2694 { 2695 __vallocate(__n); 2696 __construct_at_end(__il.begin(), __il.end()); 2697 } 2698} 2699 2700template <class _Allocator> 2701vector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a) 2702 : __begin_(nullptr), 2703 __size_(0), 2704 __cap_alloc_(0, static_cast<__storage_allocator>(__a)) 2705{ 2706 size_type __n = static_cast<size_type>(__il.size()); 2707 if (__n > 0) 2708 { 2709 __vallocate(__n); 2710 __construct_at_end(__il.begin(), __il.end()); 2711 } 2712} 2713 2714#endif // _LIBCPP_CXX03_LANG 2715 2716template <class _Allocator> 2717vector<bool, _Allocator>::~vector() 2718{ 2719 if (__begin_ != nullptr) 2720 __storage_traits::deallocate(__alloc(), __begin_, __cap()); 2721 __invalidate_all_iterators(); 2722} 2723 2724template <class _Allocator> 2725vector<bool, _Allocator>::vector(const vector& __v) 2726 : __begin_(nullptr), 2727 __size_(0), 2728 __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc())) 2729{ 2730 if (__v.size() > 0) 2731 { 2732 __vallocate(__v.size()); 2733 __construct_at_end(__v.begin(), __v.end()); 2734 } 2735} 2736 2737template <class _Allocator> 2738vector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a) 2739 : __begin_(nullptr), 2740 __size_(0), 2741 __cap_alloc_(0, __a) 2742{ 2743 if (__v.size() > 0) 2744 { 2745 __vallocate(__v.size()); 2746 __construct_at_end(__v.begin(), __v.end()); 2747 } 2748} 2749 2750template <class _Allocator> 2751vector<bool, _Allocator>& 2752vector<bool, _Allocator>::operator=(const vector& __v) 2753{ 2754 if (this != _VSTD::addressof(__v)) 2755 { 2756 __copy_assign_alloc(__v); 2757 if (__v.__size_) 2758 { 2759 if (__v.__size_ > capacity()) 2760 { 2761 __vdeallocate(); 2762 __vallocate(__v.__size_); 2763 } 2764 _VSTD::copy(__v.__begin_, __v.__begin_ + __external_cap_to_internal(__v.__size_), __begin_); 2765 } 2766 __size_ = __v.__size_; 2767 } 2768 return *this; 2769} 2770 2771#ifndef _LIBCPP_CXX03_LANG 2772 2773template <class _Allocator> 2774inline _LIBCPP_INLINE_VISIBILITY vector<bool, _Allocator>::vector(vector&& __v) 2775#if _LIBCPP_STD_VER > 14 2776 _NOEXCEPT 2777#else 2778 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) 2779#endif 2780 : __begin_(__v.__begin_), 2781 __size_(__v.__size_), 2782 __cap_alloc_(_VSTD::move(__v.__cap_alloc_)) { 2783 __v.__begin_ = nullptr; 2784 __v.__size_ = 0; 2785 __v.__cap() = 0; 2786} 2787 2788template <class _Allocator> 2789vector<bool, _Allocator>::vector(vector&& __v, const __identity_t<allocator_type>& __a) 2790 : __begin_(nullptr), 2791 __size_(0), 2792 __cap_alloc_(0, __a) 2793{ 2794 if (__a == allocator_type(__v.__alloc())) 2795 { 2796 this->__begin_ = __v.__begin_; 2797 this->__size_ = __v.__size_; 2798 this->__cap() = __v.__cap(); 2799 __v.__begin_ = nullptr; 2800 __v.__cap() = __v.__size_ = 0; 2801 } 2802 else if (__v.size() > 0) 2803 { 2804 __vallocate(__v.size()); 2805 __construct_at_end(__v.begin(), __v.end()); 2806 } 2807} 2808 2809template <class _Allocator> 2810inline _LIBCPP_INLINE_VISIBILITY 2811vector<bool, _Allocator>& 2812vector<bool, _Allocator>::operator=(vector&& __v) 2813 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) 2814{ 2815 __move_assign(__v, integral_constant<bool, 2816 __storage_traits::propagate_on_container_move_assignment::value>()); 2817 return *this; 2818} 2819 2820template <class _Allocator> 2821void 2822vector<bool, _Allocator>::__move_assign(vector& __c, false_type) 2823{ 2824 if (__alloc() != __c.__alloc()) 2825 assign(__c.begin(), __c.end()); 2826 else 2827 __move_assign(__c, true_type()); 2828} 2829 2830template <class _Allocator> 2831void 2832vector<bool, _Allocator>::__move_assign(vector& __c, true_type) 2833 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) 2834{ 2835 __vdeallocate(); 2836 __move_assign_alloc(__c); 2837 this->__begin_ = __c.__begin_; 2838 this->__size_ = __c.__size_; 2839 this->__cap() = __c.__cap(); 2840 __c.__begin_ = nullptr; 2841 __c.__cap() = __c.__size_ = 0; 2842} 2843 2844#endif // !_LIBCPP_CXX03_LANG 2845 2846template <class _Allocator> 2847void 2848vector<bool, _Allocator>::assign(size_type __n, const value_type& __x) 2849{ 2850 __size_ = 0; 2851 if (__n > 0) 2852 { 2853 size_type __c = capacity(); 2854 if (__n <= __c) 2855 __size_ = __n; 2856 else 2857 { 2858 vector __v(get_allocator()); 2859 __v.reserve(__recommend(__n)); 2860 __v.__size_ = __n; 2861 swap(__v); 2862 } 2863 _VSTD::fill_n(begin(), __n, __x); 2864 } 2865 __invalidate_all_iterators(); 2866} 2867 2868template <class _Allocator> 2869template <class _InputIterator> 2870typename enable_if 2871< 2872 __is_cpp17_input_iterator<_InputIterator>::value && 2873 !__is_cpp17_forward_iterator<_InputIterator>::value, 2874 void 2875>::type 2876vector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last) 2877{ 2878 clear(); 2879 for (; __first != __last; ++__first) 2880 push_back(*__first); 2881} 2882 2883template <class _Allocator> 2884template <class _ForwardIterator> 2885typename enable_if 2886< 2887 __is_cpp17_forward_iterator<_ForwardIterator>::value, 2888 void 2889>::type 2890vector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last) 2891{ 2892 clear(); 2893 difference_type __ns = _VSTD::distance(__first, __last); 2894 _LIBCPP_ASSERT(__ns >= 0, "invalid range specified"); 2895 const size_t __n = static_cast<size_type>(__ns); 2896 if (__n) 2897 { 2898 if (__n > capacity()) 2899 { 2900 __vdeallocate(); 2901 __vallocate(__n); 2902 } 2903 __construct_at_end(__first, __last); 2904 } 2905} 2906 2907template <class _Allocator> 2908void 2909vector<bool, _Allocator>::reserve(size_type __n) 2910{ 2911 if (__n > capacity()) 2912 { 2913 if (__n > max_size()) 2914 this->__throw_length_error(); 2915 vector __v(this->get_allocator()); 2916 __v.__vallocate(__n); 2917 __v.__construct_at_end(this->begin(), this->end()); 2918 swap(__v); 2919 __invalidate_all_iterators(); 2920 } 2921} 2922 2923template <class _Allocator> 2924void 2925vector<bool, _Allocator>::shrink_to_fit() _NOEXCEPT 2926{ 2927 if (__external_cap_to_internal(size()) > __cap()) 2928 { 2929#ifndef _LIBCPP_NO_EXCEPTIONS 2930 try 2931 { 2932#endif // _LIBCPP_NO_EXCEPTIONS 2933 vector(*this, allocator_type(__alloc())).swap(*this); 2934#ifndef _LIBCPP_NO_EXCEPTIONS 2935 } 2936 catch (...) 2937 { 2938 } 2939#endif // _LIBCPP_NO_EXCEPTIONS 2940 } 2941} 2942 2943template <class _Allocator> 2944typename vector<bool, _Allocator>::reference 2945vector<bool, _Allocator>::at(size_type __n) 2946{ 2947 if (__n >= size()) 2948 this->__throw_out_of_range(); 2949 return (*this)[__n]; 2950} 2951 2952template <class _Allocator> 2953typename vector<bool, _Allocator>::const_reference 2954vector<bool, _Allocator>::at(size_type __n) const 2955{ 2956 if (__n >= size()) 2957 this->__throw_out_of_range(); 2958 return (*this)[__n]; 2959} 2960 2961template <class _Allocator> 2962void 2963vector<bool, _Allocator>::push_back(const value_type& __x) 2964{ 2965 if (this->__size_ == this->capacity()) 2966 reserve(__recommend(this->__size_ + 1)); 2967 ++this->__size_; 2968 back() = __x; 2969} 2970 2971template <class _Allocator> 2972typename vector<bool, _Allocator>::iterator 2973vector<bool, _Allocator>::insert(const_iterator __position, const value_type& __x) 2974{ 2975 iterator __r; 2976 if (size() < capacity()) 2977 { 2978 const_iterator __old_end = end(); 2979 ++__size_; 2980 _VSTD::copy_backward(__position, __old_end, end()); 2981 __r = __const_iterator_cast(__position); 2982 } 2983 else 2984 { 2985 vector __v(get_allocator()); 2986 __v.reserve(__recommend(__size_ + 1)); 2987 __v.__size_ = __size_ + 1; 2988 __r = _VSTD::copy(cbegin(), __position, __v.begin()); 2989 _VSTD::copy_backward(__position, cend(), __v.end()); 2990 swap(__v); 2991 } 2992 *__r = __x; 2993 return __r; 2994} 2995 2996template <class _Allocator> 2997typename vector<bool, _Allocator>::iterator 2998vector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const value_type& __x) 2999{ 3000 iterator __r; 3001 size_type __c = capacity(); 3002 if (__n <= __c && size() <= __c - __n) 3003 { 3004 const_iterator __old_end = end(); 3005 __size_ += __n; 3006 _VSTD::copy_backward(__position, __old_end, end()); 3007 __r = __const_iterator_cast(__position); 3008 } 3009 else 3010 { 3011 vector __v(get_allocator()); 3012 __v.reserve(__recommend(__size_ + __n)); 3013 __v.__size_ = __size_ + __n; 3014 __r = _VSTD::copy(cbegin(), __position, __v.begin()); 3015 _VSTD::copy_backward(__position, cend(), __v.end()); 3016 swap(__v); 3017 } 3018 _VSTD::fill_n(__r, __n, __x); 3019 return __r; 3020} 3021 3022template <class _Allocator> 3023template <class _InputIterator> 3024typename enable_if 3025< 3026 __is_cpp17_input_iterator <_InputIterator>::value && 3027 !__is_cpp17_forward_iterator<_InputIterator>::value, 3028 typename vector<bool, _Allocator>::iterator 3029>::type 3030vector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last) 3031{ 3032 difference_type __off = __position - begin(); 3033 iterator __p = __const_iterator_cast(__position); 3034 iterator __old_end = end(); 3035 for (; size() != capacity() && __first != __last; ++__first) 3036 { 3037 ++this->__size_; 3038 back() = *__first; 3039 } 3040 vector __v(get_allocator()); 3041 if (__first != __last) 3042 { 3043#ifndef _LIBCPP_NO_EXCEPTIONS 3044 try 3045 { 3046#endif // _LIBCPP_NO_EXCEPTIONS 3047 __v.assign(__first, __last); 3048 difference_type __old_size = static_cast<difference_type>(__old_end - begin()); 3049 difference_type __old_p = __p - begin(); 3050 reserve(__recommend(size() + __v.size())); 3051 __p = begin() + __old_p; 3052 __old_end = begin() + __old_size; 3053#ifndef _LIBCPP_NO_EXCEPTIONS 3054 } 3055 catch (...) 3056 { 3057 erase(__old_end, end()); 3058 throw; 3059 } 3060#endif // _LIBCPP_NO_EXCEPTIONS 3061 } 3062 __p = _VSTD::rotate(__p, __old_end, end()); 3063 insert(__p, __v.begin(), __v.end()); 3064 return begin() + __off; 3065} 3066 3067template <class _Allocator> 3068template <class _ForwardIterator> 3069typename enable_if 3070< 3071 __is_cpp17_forward_iterator<_ForwardIterator>::value, 3072 typename vector<bool, _Allocator>::iterator 3073>::type 3074vector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last) 3075{ 3076 const difference_type __n_signed = _VSTD::distance(__first, __last); 3077 _LIBCPP_ASSERT(__n_signed >= 0, "invalid range specified"); 3078 const size_type __n = static_cast<size_type>(__n_signed); 3079 iterator __r; 3080 size_type __c = capacity(); 3081 if (__n <= __c && size() <= __c - __n) 3082 { 3083 const_iterator __old_end = end(); 3084 __size_ += __n; 3085 _VSTD::copy_backward(__position, __old_end, end()); 3086 __r = __const_iterator_cast(__position); 3087 } 3088 else 3089 { 3090 vector __v(get_allocator()); 3091 __v.reserve(__recommend(__size_ + __n)); 3092 __v.__size_ = __size_ + __n; 3093 __r = _VSTD::copy(cbegin(), __position, __v.begin()); 3094 _VSTD::copy_backward(__position, cend(), __v.end()); 3095 swap(__v); 3096 } 3097 _VSTD::copy(__first, __last, __r); 3098 return __r; 3099} 3100 3101template <class _Allocator> 3102inline _LIBCPP_INLINE_VISIBILITY 3103typename vector<bool, _Allocator>::iterator 3104vector<bool, _Allocator>::erase(const_iterator __position) 3105{ 3106 iterator __r = __const_iterator_cast(__position); 3107 _VSTD::copy(__position + 1, this->cend(), __r); 3108 --__size_; 3109 return __r; 3110} 3111 3112template <class _Allocator> 3113typename vector<bool, _Allocator>::iterator 3114vector<bool, _Allocator>::erase(const_iterator __first, const_iterator __last) 3115{ 3116 iterator __r = __const_iterator_cast(__first); 3117 difference_type __d = __last - __first; 3118 _VSTD::copy(__last, this->cend(), __r); 3119 __size_ -= __d; 3120 return __r; 3121} 3122 3123template <class _Allocator> 3124void 3125vector<bool, _Allocator>::swap(vector& __x) 3126#if _LIBCPP_STD_VER >= 14 3127 _NOEXCEPT 3128#else 3129 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || 3130 __is_nothrow_swappable<allocator_type>::value) 3131#endif 3132{ 3133 _VSTD::swap(this->__begin_, __x.__begin_); 3134 _VSTD::swap(this->__size_, __x.__size_); 3135 _VSTD::swap(this->__cap(), __x.__cap()); 3136 _VSTD::__swap_allocator(this->__alloc(), __x.__alloc(), 3137 integral_constant<bool, __alloc_traits::propagate_on_container_swap::value>()); 3138} 3139 3140template <class _Allocator> 3141void 3142vector<bool, _Allocator>::resize(size_type __sz, value_type __x) 3143{ 3144 size_type __cs = size(); 3145 if (__cs < __sz) 3146 { 3147 iterator __r; 3148 size_type __c = capacity(); 3149 size_type __n = __sz - __cs; 3150 if (__n <= __c && __cs <= __c - __n) 3151 { 3152 __r = end(); 3153 __size_ += __n; 3154 } 3155 else 3156 { 3157 vector __v(get_allocator()); 3158 __v.reserve(__recommend(__size_ + __n)); 3159 __v.__size_ = __size_ + __n; 3160 __r = _VSTD::copy(cbegin(), cend(), __v.begin()); 3161 swap(__v); 3162 } 3163 _VSTD::fill_n(__r, __n, __x); 3164 } 3165 else 3166 __size_ = __sz; 3167} 3168 3169template <class _Allocator> 3170void 3171vector<bool, _Allocator>::flip() _NOEXCEPT 3172{ 3173 // do middle whole words 3174 size_type __n = __size_; 3175 __storage_pointer __p = __begin_; 3176 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) 3177 *__p = ~*__p; 3178 // do last partial word 3179 if (__n > 0) 3180 { 3181 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); 3182 __storage_type __b = *__p & __m; 3183 *__p &= ~__m; 3184 *__p |= ~__b & __m; 3185 } 3186} 3187 3188template <class _Allocator> 3189bool 3190vector<bool, _Allocator>::__invariants() const 3191{ 3192 if (this->__begin_ == nullptr) 3193 { 3194 if (this->__size_ != 0 || this->__cap() != 0) 3195 return false; 3196 } 3197 else 3198 { 3199 if (this->__cap() == 0) 3200 return false; 3201 if (this->__size_ > this->capacity()) 3202 return false; 3203 } 3204 return true; 3205} 3206 3207template <class _Allocator> 3208size_t 3209vector<bool, _Allocator>::__hash_code() const _NOEXCEPT 3210{ 3211 size_t __h = 0; 3212 // do middle whole words 3213 size_type __n = __size_; 3214 __storage_pointer __p = __begin_; 3215 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) 3216 __h ^= *__p; 3217 // do last partial word 3218 if (__n > 0) 3219 { 3220 const __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); 3221 __h ^= *__p & __m; 3222 } 3223 return __h; 3224} 3225 3226template <class _Allocator> 3227struct _LIBCPP_TEMPLATE_VIS hash<vector<bool, _Allocator> > 3228 : public unary_function<vector<bool, _Allocator>, size_t> 3229{ 3230 _LIBCPP_INLINE_VISIBILITY 3231 size_t operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT 3232 {return __vec.__hash_code();} 3233}; 3234 3235template <class _Tp, class _Allocator> 3236inline _LIBCPP_INLINE_VISIBILITY 3237bool 3238operator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) 3239{ 3240 const typename vector<_Tp, _Allocator>::size_type __sz = __x.size(); 3241 return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin()); 3242} 3243 3244template <class _Tp, class _Allocator> 3245inline _LIBCPP_INLINE_VISIBILITY 3246bool 3247operator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) 3248{ 3249 return !(__x == __y); 3250} 3251 3252template <class _Tp, class _Allocator> 3253inline _LIBCPP_INLINE_VISIBILITY 3254bool 3255operator< (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) 3256{ 3257 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); 3258} 3259 3260template <class _Tp, class _Allocator> 3261inline _LIBCPP_INLINE_VISIBILITY 3262bool 3263operator> (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) 3264{ 3265 return __y < __x; 3266} 3267 3268template <class _Tp, class _Allocator> 3269inline _LIBCPP_INLINE_VISIBILITY 3270bool 3271operator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) 3272{ 3273 return !(__x < __y); 3274} 3275 3276template <class _Tp, class _Allocator> 3277inline _LIBCPP_INLINE_VISIBILITY 3278bool 3279operator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) 3280{ 3281 return !(__y < __x); 3282} 3283 3284template <class _Tp, class _Allocator> 3285inline _LIBCPP_INLINE_VISIBILITY 3286void 3287swap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y) 3288 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) 3289{ 3290 __x.swap(__y); 3291} 3292 3293#if _LIBCPP_STD_VER > 17 3294template <class _Tp, class _Allocator, class _Up> 3295inline _LIBCPP_INLINE_VISIBILITY typename vector<_Tp, _Allocator>::size_type 3296erase(vector<_Tp, _Allocator>& __c, const _Up& __v) { 3297 auto __old_size = __c.size(); 3298 __c.erase(_VSTD::remove(__c.begin(), __c.end(), __v), __c.end()); 3299 return __old_size - __c.size(); 3300} 3301 3302template <class _Tp, class _Allocator, class _Predicate> 3303inline _LIBCPP_INLINE_VISIBILITY typename vector<_Tp, _Allocator>::size_type 3304erase_if(vector<_Tp, _Allocator>& __c, _Predicate __pred) { 3305 auto __old_size = __c.size(); 3306 __c.erase(_VSTD::remove_if(__c.begin(), __c.end(), __pred), __c.end()); 3307 return __old_size - __c.size(); 3308} 3309#endif 3310 3311_LIBCPP_END_NAMESPACE_STD 3312 3313_LIBCPP_POP_MACROS 3314 3315#endif // _LIBCPP_VECTOR 3316