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