comparison libcxx/include/vector @ 207:2e18cbf3894f

LLVM12
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 08 Jun 2021 06:07:14 +0900
parents 0572611fdcc8
children 5f17cb93ff66
comparison
equal deleted inserted replaced
173:0572611fdcc8 207:2e18cbf3894f
270 } // std 270 } // std
271 271
272 */ 272 */
273 273
274 #include <__config> 274 #include <__config>
275 #include <__bit_reference>
276 #include <__debug>
277 #include <__functional_base>
278 #include <__split_buffer>
279 #include <algorithm>
280 #include <climits>
281 #include <compare>
282 #include <cstring>
283 #include <initializer_list>
275 #include <iosfwd> // for forward declaration of vector 284 #include <iosfwd> // for forward declaration of vector
276 #include <__bit_reference>
277 #include <type_traits>
278 #include <climits>
279 #include <limits> 285 #include <limits>
280 #include <initializer_list>
281 #include <memory> 286 #include <memory>
282 #include <stdexcept> 287 #include <stdexcept>
283 #include <algorithm> 288 #include <type_traits>
284 #include <cstring>
285 #include <version> 289 #include <version>
286 #include <__split_buffer>
287 #include <__functional_base>
288
289 #include <__debug>
290 290
291 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 291 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
292 #pragma GCC system_header 292 #pragma GCC system_header
293 #endif 293 #endif
294 294
452 template <class _Tp, class _Allocator> 452 template <class _Tp, class _Allocator>
453 inline _LIBCPP_INLINE_VISIBILITY 453 inline _LIBCPP_INLINE_VISIBILITY
454 __vector_base<_Tp, _Allocator>::__vector_base(allocator_type&& __a) _NOEXCEPT 454 __vector_base<_Tp, _Allocator>::__vector_base(allocator_type&& __a) _NOEXCEPT
455 : __begin_(nullptr), 455 : __begin_(nullptr),
456 __end_(nullptr), 456 __end_(nullptr),
457 __end_cap_(nullptr, std::move(__a)) {} 457 __end_cap_(nullptr, _VSTD::move(__a)) {}
458 #endif 458 #endif
459 459
460 template <class _Tp, class _Allocator> 460 template <class _Tp, class _Allocator>
461 __vector_base<_Tp, _Allocator>::~__vector_base() 461 __vector_base<_Tp, _Allocator>::~__vector_base()
462 { 462 {
494 "Allocator::value_type must be same type as value_type"); 494 "Allocator::value_type must be same type as value_type");
495 495
496 _LIBCPP_INLINE_VISIBILITY 496 _LIBCPP_INLINE_VISIBILITY
497 vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) 497 vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
498 { 498 {
499 #if _LIBCPP_DEBUG_LEVEL >= 2 499 #if _LIBCPP_DEBUG_LEVEL == 2
500 __get_db()->__insert_c(this); 500 __get_db()->__insert_c(this);
501 #endif 501 #endif
502 } 502 }
503 _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a) 503 _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a)
504 #if _LIBCPP_STD_VER <= 14 504 #if _LIBCPP_STD_VER <= 14
506 #else 506 #else
507 _NOEXCEPT 507 _NOEXCEPT
508 #endif 508 #endif
509 : __base(__a) 509 : __base(__a)
510 { 510 {
511 #if _LIBCPP_DEBUG_LEVEL >= 2 511 #if _LIBCPP_DEBUG_LEVEL == 2
512 __get_db()->__insert_c(this); 512 __get_db()->__insert_c(this);
513 #endif 513 #endif
514 } 514 }
515 explicit vector(size_type __n); 515 explicit vector(size_type __n);
516 #if _LIBCPP_STD_VER > 11 516 #if _LIBCPP_STD_VER > 11
549 549
550 _LIBCPP_INLINE_VISIBILITY 550 _LIBCPP_INLINE_VISIBILITY
551 ~vector() 551 ~vector()
552 { 552 {
553 __annotate_delete(); 553 __annotate_delete();
554 #if _LIBCPP_DEBUG_LEVEL >= 2 554 #if _LIBCPP_DEBUG_LEVEL == 2
555 __get_db()->__erase_c(this); 555 __get_db()->__erase_c(this);
556 #endif 556 #endif
557 } 557 }
558 558
559 vector(const vector& __x); 559 vector(const vector& __x);
584 584
585 _LIBCPP_INLINE_VISIBILITY 585 _LIBCPP_INLINE_VISIBILITY
586 vector& operator=(initializer_list<value_type> __il) 586 vector& operator=(initializer_list<value_type> __il)
587 {assign(__il.begin(), __il.end()); return *this;} 587 {assign(__il.begin(), __il.end()); return *this;}
588 588
589 #endif // !_LIBCPP_CXX03_LANG 589 #endif // !_LIBCPP_CXX03_LANG
590 590
591 template <class _InputIterator> 591 template <class _InputIterator>
592 typename enable_if 592 typename enable_if
593 < 593 <
594 __is_cpp17_input_iterator <_InputIterator>::value && 594 __is_cpp17_input_iterator <_InputIterator>::value &&
671 reference at(size_type __n); 671 reference at(size_type __n);
672 const_reference at(size_type __n) const; 672 const_reference at(size_type __n) const;
673 673
674 _LIBCPP_INLINE_VISIBILITY reference front() _NOEXCEPT 674 _LIBCPP_INLINE_VISIBILITY reference front() _NOEXCEPT
675 { 675 {
676 _LIBCPP_ASSERT(!empty(), "front() called for empty vector"); 676 _LIBCPP_ASSERT(!empty(), "front() called on an empty vector");
677 return *this->__begin_; 677 return *this->__begin_;
678 } 678 }
679 _LIBCPP_INLINE_VISIBILITY const_reference front() const _NOEXCEPT 679 _LIBCPP_INLINE_VISIBILITY const_reference front() const _NOEXCEPT
680 { 680 {
681 _LIBCPP_ASSERT(!empty(), "front() called for empty vector"); 681 _LIBCPP_ASSERT(!empty(), "front() called on an empty vector");
682 return *this->__begin_; 682 return *this->__begin_;
683 } 683 }
684 _LIBCPP_INLINE_VISIBILITY reference back() _NOEXCEPT 684 _LIBCPP_INLINE_VISIBILITY reference back() _NOEXCEPT
685 { 685 {
686 _LIBCPP_ASSERT(!empty(), "back() called for empty vector"); 686 _LIBCPP_ASSERT(!empty(), "back() called on an empty vector");
687 return *(this->__end_ - 1); 687 return *(this->__end_ - 1);
688 } 688 }
689 _LIBCPP_INLINE_VISIBILITY const_reference back() const _NOEXCEPT 689 _LIBCPP_INLINE_VISIBILITY const_reference back() const _NOEXCEPT
690 { 690 {
691 _LIBCPP_ASSERT(!empty(), "back() called for empty vector"); 691 _LIBCPP_ASSERT(!empty(), "back() called on an empty vector");
692 return *(this->__end_ - 1); 692 return *(this->__end_ - 1);
693 } 693 }
694 694
695 _LIBCPP_INLINE_VISIBILITY 695 _LIBCPP_INLINE_VISIBILITY
696 value_type* data() _NOEXCEPT 696 value_type* data() _NOEXCEPT
731 731
732 #ifndef _LIBCPP_CXX03_LANG 732 #ifndef _LIBCPP_CXX03_LANG
733 iterator insert(const_iterator __position, value_type&& __x); 733 iterator insert(const_iterator __position, value_type&& __x);
734 template <class... _Args> 734 template <class... _Args>
735 iterator emplace(const_iterator __position, _Args&&... __args); 735 iterator emplace(const_iterator __position, _Args&&... __args);
736 #endif // !_LIBCPP_CXX03_LANG 736 #endif // !_LIBCPP_CXX03_LANG
737 737
738 iterator insert(const_iterator __position, size_type __n, const_reference __x); 738 iterator insert(const_iterator __position, size_type __n, const_reference __x);
739 template <class _InputIterator> 739 template <class _InputIterator>
740 typename enable_if 740 typename enable_if
741 < 741 <
787 __is_nothrow_swappable<allocator_type>::value); 787 __is_nothrow_swappable<allocator_type>::value);
788 #endif 788 #endif
789 789
790 bool __invariants() const; 790 bool __invariants() const;
791 791
792 #if _LIBCPP_DEBUG_LEVEL >= 2 792 #if _LIBCPP_DEBUG_LEVEL == 2
793 793
794 bool __dereferenceable(const const_iterator* __i) const; 794 bool __dereferenceable(const const_iterator* __i) const;
795 bool __decrementable(const const_iterator* __i) const; 795 bool __decrementable(const const_iterator* __i) const;
796 bool __addable(const const_iterator* __i, ptrdiff_t __n) const; 796 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
797 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const; 797 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
798 798
799 #endif // _LIBCPP_DEBUG_LEVEL >= 2 799 #endif // _LIBCPP_DEBUG_LEVEL == 2
800 800
801 private: 801 private:
802 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators(); 802 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
803 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(pointer __new_last); 803 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(pointer __new_last);
804 void __vallocate(size_type __n); 804 void __vallocate(size_type __n);
929 } 929 }
930 }; 930 };
931 931
932 #ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES 932 #ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
933 template<class _InputIterator, 933 template<class _InputIterator,
934 class _Alloc = typename std::allocator<typename iterator_traits<_InputIterator>::value_type>, 934 class _Alloc = allocator<__iter_value_type<_InputIterator>>,
935 class = typename enable_if<__is_allocator<_Alloc>::value, void>::type 935 class = _EnableIf<__is_allocator<_Alloc>::value>
936 > 936 >
937 vector(_InputIterator, _InputIterator) 937 vector(_InputIterator, _InputIterator)
938 -> vector<typename iterator_traits<_InputIterator>::value_type, _Alloc>; 938 -> vector<__iter_value_type<_InputIterator>, _Alloc>;
939 939
940 template<class _InputIterator, 940 template<class _InputIterator,
941 class _Alloc, 941 class _Alloc,
942 class = typename enable_if<__is_allocator<_Alloc>::value, void>::type 942 class = _EnableIf<__is_allocator<_Alloc>::value>
943 > 943 >
944 vector(_InputIterator, _InputIterator, _Alloc) 944 vector(_InputIterator, _InputIterator, _Alloc)
945 -> vector<typename iterator_traits<_InputIterator>::value_type, _Alloc>; 945 -> vector<__iter_value_type<_InputIterator>, _Alloc>;
946 #endif 946 #endif
947 947
948 template <class _Tp, class _Allocator> 948 template <class _Tp, class _Allocator>
949 void 949 void
950 vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v) 950 vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v)
951 { 951 {
952 952
953 __annotate_delete(); 953 __annotate_delete();
954 __alloc_traits::__construct_backward_with_exception_guarantees( 954 _VSTD::__construct_backward_with_exception_guarantees(this->__alloc(), this->__begin_, this->__end_, __v.__begin_);
955 this->__alloc(), this->__begin_, this->__end_, __v.__begin_);
956 _VSTD::swap(this->__begin_, __v.__begin_); 955 _VSTD::swap(this->__begin_, __v.__begin_);
957 _VSTD::swap(this->__end_, __v.__end_); 956 _VSTD::swap(this->__end_, __v.__end_);
958 _VSTD::swap(this->__end_cap(), __v.__end_cap()); 957 _VSTD::swap(this->__end_cap(), __v.__end_cap());
959 __v.__first_ = __v.__begin_; 958 __v.__first_ = __v.__begin_;
960 __annotate_new(size()); 959 __annotate_new(size());
965 typename vector<_Tp, _Allocator>::pointer 964 typename vector<_Tp, _Allocator>::pointer
966 vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p) 965 vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p)
967 { 966 {
968 __annotate_delete(); 967 __annotate_delete();
969 pointer __r = __v.__begin_; 968 pointer __r = __v.__begin_;
970 __alloc_traits::__construct_backward_with_exception_guarantees( 969 _VSTD::__construct_backward_with_exception_guarantees(this->__alloc(), this->__begin_, __p, __v.__begin_);
971 this->__alloc(), this->__begin_, __p, __v.__begin_); 970 _VSTD::__construct_forward_with_exception_guarantees(this->__alloc(), __p, this->__end_, __v.__end_);
972 __alloc_traits::__construct_forward_with_exception_guarantees(
973 this->__alloc(), __p, this->__end_, __v.__end_);
974 _VSTD::swap(this->__begin_, __v.__begin_); 971 _VSTD::swap(this->__begin_, __v.__begin_);
975 _VSTD::swap(this->__end_, __v.__end_); 972 _VSTD::swap(this->__end_, __v.__end_);
976 _VSTD::swap(this->__end_cap(), __v.__end_cap()); 973 _VSTD::swap(this->__end_cap(), __v.__end_cap());
977 __v.__first_ = __v.__begin_; 974 __v.__first_ = __v.__begin_;
978 __annotate_new(size()); 975 __annotate_new(size());
1041 template <class _Tp, class _Allocator> 1038 template <class _Tp, class _Allocator>
1042 void 1039 void
1043 vector<_Tp, _Allocator>::__construct_at_end(size_type __n) 1040 vector<_Tp, _Allocator>::__construct_at_end(size_type __n)
1044 { 1041 {
1045 _ConstructTransaction __tx(*this, __n); 1042 _ConstructTransaction __tx(*this, __n);
1046 for (; __tx.__pos_ != __tx.__new_end_; ++__tx.__pos_) { 1043 const_pointer __new_end = __tx.__new_end_;
1047 __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__tx.__pos_)); 1044 for (pointer __pos = __tx.__pos_; __pos != __new_end; ++__pos, __tx.__pos_ = __pos) {
1045 __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__pos));
1048 } 1046 }
1049 } 1047 }
1050 1048
1051 // Copy constructs __n objects starting at __end_ from __x 1049 // Copy constructs __n objects starting at __end_ from __x
1052 // throws if construction throws 1050 // throws if construction throws
1058 inline 1056 inline
1059 void 1057 void
1060 vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x) 1058 vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x)
1061 { 1059 {
1062 _ConstructTransaction __tx(*this, __n); 1060 _ConstructTransaction __tx(*this, __n);
1063 for (; __tx.__pos_ != __tx.__new_end_; ++__tx.__pos_) { 1061 const_pointer __new_end = __tx.__new_end_;
1064 __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__tx.__pos_), __x); 1062 for (pointer __pos = __tx.__pos_; __pos != __new_end; ++__pos, __tx.__pos_ = __pos) {
1063 __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__pos), __x);
1065 } 1064 }
1066 } 1065 }
1067 1066
1068 template <class _Tp, class _Allocator> 1067 template <class _Tp, class _Allocator>
1069 template <class _ForwardIterator> 1068 template <class _ForwardIterator>
1073 void 1072 void
1074 >::type 1073 >::type
1075 vector<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n) 1074 vector<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n)
1076 { 1075 {
1077 _ConstructTransaction __tx(*this, __n); 1076 _ConstructTransaction __tx(*this, __n);
1078 __alloc_traits::__construct_range_forward(this->__alloc(), __first, __last, __tx.__pos_); 1077 _VSTD::__construct_range_forward(this->__alloc(), __first, __last, __tx.__pos_);
1079 } 1078 }
1080 1079
1081 // Default constructs __n objects starting at __end_ 1080 // Default constructs __n objects starting at __end_
1082 // throws if construction throws 1081 // throws if construction throws
1083 // Postcondition: size() == size() + __n 1082 // Postcondition: size() == size() + __n
1117 } 1116 }
1118 1117
1119 template <class _Tp, class _Allocator> 1118 template <class _Tp, class _Allocator>
1120 vector<_Tp, _Allocator>::vector(size_type __n) 1119 vector<_Tp, _Allocator>::vector(size_type __n)
1121 { 1120 {
1122 #if _LIBCPP_DEBUG_LEVEL >= 2 1121 #if _LIBCPP_DEBUG_LEVEL == 2
1123 __get_db()->__insert_c(this); 1122 __get_db()->__insert_c(this);
1124 #endif 1123 #endif
1125 if (__n > 0) 1124 if (__n > 0)
1126 { 1125 {
1127 __vallocate(__n); 1126 __vallocate(__n);
1132 #if _LIBCPP_STD_VER > 11 1131 #if _LIBCPP_STD_VER > 11
1133 template <class _Tp, class _Allocator> 1132 template <class _Tp, class _Allocator>
1134 vector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a) 1133 vector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a)
1135 : __base(__a) 1134 : __base(__a)
1136 { 1135 {
1137 #if _LIBCPP_DEBUG_LEVEL >= 2 1136 #if _LIBCPP_DEBUG_LEVEL == 2
1138 __get_db()->__insert_c(this); 1137 __get_db()->__insert_c(this);
1139 #endif 1138 #endif
1140 if (__n > 0) 1139 if (__n > 0)
1141 { 1140 {
1142 __vallocate(__n); 1141 __vallocate(__n);
1146 #endif 1145 #endif
1147 1146
1148 template <class _Tp, class _Allocator> 1147 template <class _Tp, class _Allocator>
1149 vector<_Tp, _Allocator>::vector(size_type __n, const value_type& __x) 1148 vector<_Tp, _Allocator>::vector(size_type __n, const value_type& __x)
1150 { 1149 {
1151 #if _LIBCPP_DEBUG_LEVEL >= 2 1150 #if _LIBCPP_DEBUG_LEVEL == 2
1152 __get_db()->__insert_c(this); 1151 __get_db()->__insert_c(this);
1153 #endif 1152 #endif
1154 if (__n > 0) 1153 if (__n > 0)
1155 { 1154 {
1156 __vallocate(__n); 1155 __vallocate(__n);
1160 1159
1161 template <class _Tp, class _Allocator> 1160 template <class _Tp, class _Allocator>
1162 vector<_Tp, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a) 1161 vector<_Tp, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a)
1163 : __base(__a) 1162 : __base(__a)
1164 { 1163 {
1165 #if _LIBCPP_DEBUG_LEVEL >= 2 1164 #if _LIBCPP_DEBUG_LEVEL == 2
1166 __get_db()->__insert_c(this); 1165 __get_db()->__insert_c(this);
1167 #endif 1166 #endif
1168 if (__n > 0) 1167 if (__n > 0)
1169 { 1168 {
1170 __vallocate(__n); 1169 __vallocate(__n);
1180 is_constructible< 1179 is_constructible<
1181 value_type, 1180 value_type,
1182 typename iterator_traits<_InputIterator>::reference>::value, 1181 typename iterator_traits<_InputIterator>::reference>::value,
1183 _InputIterator>::type __last) 1182 _InputIterator>::type __last)
1184 { 1183 {
1185 #if _LIBCPP_DEBUG_LEVEL >= 2 1184 #if _LIBCPP_DEBUG_LEVEL == 2
1186 __get_db()->__insert_c(this); 1185 __get_db()->__insert_c(this);
1187 #endif 1186 #endif
1188 for (; __first != __last; ++__first) 1187 for (; __first != __last; ++__first)
1189 __emplace_back(*__first); 1188 __emplace_back(*__first);
1190 } 1189 }
1197 is_constructible< 1196 is_constructible<
1198 value_type, 1197 value_type,
1199 typename iterator_traits<_InputIterator>::reference>::value>::type*) 1198 typename iterator_traits<_InputIterator>::reference>::value>::type*)
1200 : __base(__a) 1199 : __base(__a)
1201 { 1200 {
1202 #if _LIBCPP_DEBUG_LEVEL >= 2 1201 #if _LIBCPP_DEBUG_LEVEL == 2
1203 __get_db()->__insert_c(this); 1202 __get_db()->__insert_c(this);
1204 #endif 1203 #endif
1205 for (; __first != __last; ++__first) 1204 for (; __first != __last; ++__first)
1206 __emplace_back(*__first); 1205 __emplace_back(*__first);
1207 } 1206 }
1213 is_constructible< 1212 is_constructible<
1214 value_type, 1213 value_type,
1215 typename iterator_traits<_ForwardIterator>::reference>::value, 1214 typename iterator_traits<_ForwardIterator>::reference>::value,
1216 _ForwardIterator>::type __last) 1215 _ForwardIterator>::type __last)
1217 { 1216 {
1218 #if _LIBCPP_DEBUG_LEVEL >= 2 1217 #if _LIBCPP_DEBUG_LEVEL == 2
1219 __get_db()->__insert_c(this); 1218 __get_db()->__insert_c(this);
1220 #endif 1219 #endif
1221 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); 1220 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
1222 if (__n > 0) 1221 if (__n > 0)
1223 { 1222 {
1233 is_constructible< 1232 is_constructible<
1234 value_type, 1233 value_type,
1235 typename iterator_traits<_ForwardIterator>::reference>::value>::type*) 1234 typename iterator_traits<_ForwardIterator>::reference>::value>::type*)
1236 : __base(__a) 1235 : __base(__a)
1237 { 1236 {
1238 #if _LIBCPP_DEBUG_LEVEL >= 2 1237 #if _LIBCPP_DEBUG_LEVEL == 2
1239 __get_db()->__insert_c(this); 1238 __get_db()->__insert_c(this);
1240 #endif 1239 #endif
1241 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); 1240 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
1242 if (__n > 0) 1241 if (__n > 0)
1243 { 1242 {
1248 1247
1249 template <class _Tp, class _Allocator> 1248 template <class _Tp, class _Allocator>
1250 vector<_Tp, _Allocator>::vector(const vector& __x) 1249 vector<_Tp, _Allocator>::vector(const vector& __x)
1251 : __base(__alloc_traits::select_on_container_copy_construction(__x.__alloc())) 1250 : __base(__alloc_traits::select_on_container_copy_construction(__x.__alloc()))
1252 { 1251 {
1253 #if _LIBCPP_DEBUG_LEVEL >= 2 1252 #if _LIBCPP_DEBUG_LEVEL == 2
1254 __get_db()->__insert_c(this); 1253 __get_db()->__insert_c(this);
1255 #endif 1254 #endif
1256 size_type __n = __x.size(); 1255 size_type __n = __x.size();
1257 if (__n > 0) 1256 if (__n > 0)
1258 { 1257 {
1263 1262
1264 template <class _Tp, class _Allocator> 1263 template <class _Tp, class _Allocator>
1265 vector<_Tp, _Allocator>::vector(const vector& __x, const allocator_type& __a) 1264 vector<_Tp, _Allocator>::vector(const vector& __x, const allocator_type& __a)
1266 : __base(__a) 1265 : __base(__a)
1267 { 1266 {
1268 #if _LIBCPP_DEBUG_LEVEL >= 2 1267 #if _LIBCPP_DEBUG_LEVEL == 2
1269 __get_db()->__insert_c(this); 1268 __get_db()->__insert_c(this);
1270 #endif 1269 #endif
1271 size_type __n = __x.size(); 1270 size_type __n = __x.size();
1272 if (__n > 0) 1271 if (__n > 0)
1273 { 1272 {
1286 #else 1285 #else
1287 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) 1286 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
1288 #endif 1287 #endif
1289 : __base(_VSTD::move(__x.__alloc())) 1288 : __base(_VSTD::move(__x.__alloc()))
1290 { 1289 {
1291 #if _LIBCPP_DEBUG_LEVEL >= 2 1290 #if _LIBCPP_DEBUG_LEVEL == 2
1292 __get_db()->__insert_c(this); 1291 __get_db()->__insert_c(this);
1293 __get_db()->swap(this, &__x); 1292 __get_db()->swap(this, &__x);
1294 #endif 1293 #endif
1295 this->__begin_ = __x.__begin_; 1294 this->__begin_ = __x.__begin_;
1296 this->__end_ = __x.__end_; 1295 this->__end_ = __x.__end_;
1301 template <class _Tp, class _Allocator> 1300 template <class _Tp, class _Allocator>
1302 inline _LIBCPP_INLINE_VISIBILITY 1301 inline _LIBCPP_INLINE_VISIBILITY
1303 vector<_Tp, _Allocator>::vector(vector&& __x, const allocator_type& __a) 1302 vector<_Tp, _Allocator>::vector(vector&& __x, const allocator_type& __a)
1304 : __base(__a) 1303 : __base(__a)
1305 { 1304 {
1306 #if _LIBCPP_DEBUG_LEVEL >= 2 1305 #if _LIBCPP_DEBUG_LEVEL == 2
1307 __get_db()->__insert_c(this); 1306 __get_db()->__insert_c(this);
1308 #endif 1307 #endif
1309 if (__a == __x.__alloc()) 1308 if (__a == __x.__alloc())
1310 { 1309 {
1311 this->__begin_ = __x.__begin_; 1310 this->__begin_ = __x.__begin_;
1312 this->__end_ = __x.__end_; 1311 this->__end_ = __x.__end_;
1313 this->__end_cap() = __x.__end_cap(); 1312 this->__end_cap() = __x.__end_cap();
1314 __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr; 1313 __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
1315 #if _LIBCPP_DEBUG_LEVEL >= 2 1314 #if _LIBCPP_DEBUG_LEVEL == 2
1316 __get_db()->swap(this, &__x); 1315 __get_db()->swap(this, &__x);
1317 #endif 1316 #endif
1318 } 1317 }
1319 else 1318 else
1320 { 1319 {
1325 1324
1326 template <class _Tp, class _Allocator> 1325 template <class _Tp, class _Allocator>
1327 inline _LIBCPP_INLINE_VISIBILITY 1326 inline _LIBCPP_INLINE_VISIBILITY
1328 vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il) 1327 vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il)
1329 { 1328 {
1330 #if _LIBCPP_DEBUG_LEVEL >= 2 1329 #if _LIBCPP_DEBUG_LEVEL == 2
1331 __get_db()->__insert_c(this); 1330 __get_db()->__insert_c(this);
1332 #endif 1331 #endif
1333 if (__il.size() > 0) 1332 if (__il.size() > 0)
1334 { 1333 {
1335 __vallocate(__il.size()); 1334 __vallocate(__il.size());
1340 template <class _Tp, class _Allocator> 1339 template <class _Tp, class _Allocator>
1341 inline _LIBCPP_INLINE_VISIBILITY 1340 inline _LIBCPP_INLINE_VISIBILITY
1342 vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a) 1341 vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
1343 : __base(__a) 1342 : __base(__a)
1344 { 1343 {
1345 #if _LIBCPP_DEBUG_LEVEL >= 2 1344 #if _LIBCPP_DEBUG_LEVEL == 2
1346 __get_db()->__insert_c(this); 1345 __get_db()->__insert_c(this);
1347 #endif 1346 #endif
1348 if (__il.size() > 0) 1347 if (__il.size() > 0)
1349 { 1348 {
1350 __vallocate(__il.size()); 1349 __vallocate(__il.size());
1386 __base::__move_assign_alloc(__c); // this can throw 1385 __base::__move_assign_alloc(__c); // this can throw
1387 this->__begin_ = __c.__begin_; 1386 this->__begin_ = __c.__begin_;
1388 this->__end_ = __c.__end_; 1387 this->__end_ = __c.__end_;
1389 this->__end_cap() = __c.__end_cap(); 1388 this->__end_cap() = __c.__end_cap();
1390 __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr; 1389 __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr;
1391 #if _LIBCPP_DEBUG_LEVEL >= 2 1390 #if _LIBCPP_DEBUG_LEVEL == 2
1392 __get_db()->swap(this, &__c); 1391 __get_db()->swap(this, &__c);
1393 #endif 1392 #endif
1394 } 1393 }
1395 1394
1396 #endif // !_LIBCPP_CXX03_LANG 1395 #endif // !_LIBCPP_CXX03_LANG
1397 1396
1398 template <class _Tp, class _Allocator> 1397 template <class _Tp, class _Allocator>
1399 inline _LIBCPP_INLINE_VISIBILITY 1398 inline _LIBCPP_INLINE_VISIBILITY
1400 vector<_Tp, _Allocator>& 1399 vector<_Tp, _Allocator>&
1401 vector<_Tp, _Allocator>::operator=(const vector& __x) 1400 vector<_Tp, _Allocator>::operator=(const vector& __x)
1489 template <class _Tp, class _Allocator> 1488 template <class _Tp, class _Allocator>
1490 inline _LIBCPP_INLINE_VISIBILITY 1489 inline _LIBCPP_INLINE_VISIBILITY
1491 typename vector<_Tp, _Allocator>::iterator 1490 typename vector<_Tp, _Allocator>::iterator
1492 vector<_Tp, _Allocator>::__make_iter(pointer __p) _NOEXCEPT 1491 vector<_Tp, _Allocator>::__make_iter(pointer __p) _NOEXCEPT
1493 { 1492 {
1494 #if _LIBCPP_DEBUG_LEVEL >= 2 1493 #if _LIBCPP_DEBUG_LEVEL == 2
1495 return iterator(this, __p); 1494 return iterator(this, __p);
1496 #else 1495 #else
1497 return iterator(__p); 1496 return iterator(__p);
1498 #endif 1497 #endif
1499 } 1498 }
1501 template <class _Tp, class _Allocator> 1500 template <class _Tp, class _Allocator>
1502 inline _LIBCPP_INLINE_VISIBILITY 1501 inline _LIBCPP_INLINE_VISIBILITY
1503 typename vector<_Tp, _Allocator>::const_iterator 1502 typename vector<_Tp, _Allocator>::const_iterator
1504 vector<_Tp, _Allocator>::__make_iter(const_pointer __p) const _NOEXCEPT 1503 vector<_Tp, _Allocator>::__make_iter(const_pointer __p) const _NOEXCEPT
1505 { 1504 {
1506 #if _LIBCPP_DEBUG_LEVEL >= 2 1505 #if _LIBCPP_DEBUG_LEVEL == 2
1507 return const_iterator(this, __p); 1506 return const_iterator(this, __p);
1508 #else 1507 #else
1509 return const_iterator(__p); 1508 return const_iterator(__p);
1510 #endif 1509 #endif
1511 } 1510 }
1597 if (capacity() > size()) 1596 if (capacity() > size())
1598 { 1597 {
1599 #ifndef _LIBCPP_NO_EXCEPTIONS 1598 #ifndef _LIBCPP_NO_EXCEPTIONS
1600 try 1599 try
1601 { 1600 {
1602 #endif // _LIBCPP_NO_EXCEPTIONS 1601 #endif // _LIBCPP_NO_EXCEPTIONS
1603 allocator_type& __a = this->__alloc(); 1602 allocator_type& __a = this->__alloc();
1604 __split_buffer<value_type, allocator_type&> __v(size(), size(), __a); 1603 __split_buffer<value_type, allocator_type&> __v(size(), size(), __a);
1605 __swap_out_circular_buffer(__v); 1604 __swap_out_circular_buffer(__v);
1606 #ifndef _LIBCPP_NO_EXCEPTIONS 1605 #ifndef _LIBCPP_NO_EXCEPTIONS
1607 } 1606 }
1608 catch (...) 1607 catch (...)
1609 { 1608 {
1610 } 1609 }
1611 #endif // _LIBCPP_NO_EXCEPTIONS 1610 #endif // _LIBCPP_NO_EXCEPTIONS
1612 } 1611 }
1613 } 1612 }
1614 1613
1615 template <class _Tp, class _Allocator> 1614 template <class _Tp, class _Allocator>
1616 template <class _Up> 1615 template <class _Up>
1689 #if _LIBCPP_STD_VER > 14 1688 #if _LIBCPP_STD_VER > 14
1690 return this->back(); 1689 return this->back();
1691 #endif 1690 #endif
1692 } 1691 }
1693 1692
1694 #endif // !_LIBCPP_CXX03_LANG 1693 #endif // !_LIBCPP_CXX03_LANG
1695 1694
1696 template <class _Tp, class _Allocator> 1695 template <class _Tp, class _Allocator>
1697 inline 1696 inline
1698 void 1697 void
1699 vector<_Tp, _Allocator>::pop_back() 1698 vector<_Tp, _Allocator>::pop_back()
1700 { 1699 {
1701 _LIBCPP_ASSERT(!empty(), "vector::pop_back called for empty vector"); 1700 _LIBCPP_ASSERT(!empty(), "vector::pop_back called on an empty vector");
1702 this->__destruct_at_end(this->__end_ - 1); 1701 this->__destruct_at_end(this->__end_ - 1);
1703 } 1702 }
1704 1703
1705 template <class _Tp, class _Allocator> 1704 template <class _Tp, class _Allocator>
1706 inline _LIBCPP_INLINE_VISIBILITY 1705 inline _LIBCPP_INLINE_VISIBILITY
1707 typename vector<_Tp, _Allocator>::iterator 1706 typename vector<_Tp, _Allocator>::iterator
1708 vector<_Tp, _Allocator>::erase(const_iterator __position) 1707 vector<_Tp, _Allocator>::erase(const_iterator __position)
1709 { 1708 {
1710 #if _LIBCPP_DEBUG_LEVEL >= 2 1709 #if _LIBCPP_DEBUG_LEVEL == 2
1711 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, 1710 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1712 "vector::erase(iterator) called with an iterator not" 1711 "vector::erase(iterator) called with an iterator not"
1713 " referring to this vector"); 1712 " referring to this vector");
1714 #endif 1713 #endif
1715 _LIBCPP_ASSERT(__position != end(), 1714 _LIBCPP_ASSERT(__position != end(),
1724 1723
1725 template <class _Tp, class _Allocator> 1724 template <class _Tp, class _Allocator>
1726 typename vector<_Tp, _Allocator>::iterator 1725 typename vector<_Tp, _Allocator>::iterator
1727 vector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last) 1726 vector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last)
1728 { 1727 {
1729 #if _LIBCPP_DEBUG_LEVEL >= 2 1728 #if _LIBCPP_DEBUG_LEVEL == 2
1730 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this, 1729 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
1731 "vector::erase(iterator, iterator) called with an iterator not" 1730 "vector::erase(iterator, iterator) called with an iterator not"
1732 " referring to this vector"); 1731 " referring to this vector");
1733 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__last) == this, 1732 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__last) == this,
1734 "vector::erase(iterator, iterator) called with an iterator not" 1733 "vector::erase(iterator, iterator) called with an iterator not"
1751 pointer __old_last = this->__end_; 1750 pointer __old_last = this->__end_;
1752 difference_type __n = __old_last - __to; 1751 difference_type __n = __old_last - __to;
1753 { 1752 {
1754 pointer __i = __from_s + __n; 1753 pointer __i = __from_s + __n;
1755 _ConstructTransaction __tx(*this, __from_e - __i); 1754 _ConstructTransaction __tx(*this, __from_e - __i);
1756 for (; __i < __from_e; ++__i, ++__tx.__pos_) { 1755 for (pointer __pos = __tx.__pos_; __i < __from_e;
1756 ++__i, ++__pos, __tx.__pos_ = __pos) {
1757 __alloc_traits::construct(this->__alloc(), 1757 __alloc_traits::construct(this->__alloc(),
1758 _VSTD::__to_address(__tx.__pos_), 1758 _VSTD::__to_address(__pos),
1759 _VSTD::move(*__i)); 1759 _VSTD::move(*__i));
1760 } 1760 }
1761 } 1761 }
1762 _VSTD::move_backward(__from_s, __from_s + __n, __old_last); 1762 _VSTD::move_backward(__from_s, __from_s + __n, __old_last);
1763 } 1763 }
1764 1764
1765 template <class _Tp, class _Allocator> 1765 template <class _Tp, class _Allocator>
1766 typename vector<_Tp, _Allocator>::iterator 1766 typename vector<_Tp, _Allocator>::iterator
1767 vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x) 1767 vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x)
1768 { 1768 {
1769 #if _LIBCPP_DEBUG_LEVEL >= 2 1769 #if _LIBCPP_DEBUG_LEVEL == 2
1770 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, 1770 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1771 "vector::insert(iterator, x) called with an iterator not" 1771 "vector::insert(iterator, x) called with an iterator not"
1772 " referring to this vector"); 1772 " referring to this vector");
1773 #endif 1773 #endif
1774 pointer __p = this->__begin_ + (__position - begin()); 1774 pointer __p = this->__begin_ + (__position - begin());
1801 1801
1802 template <class _Tp, class _Allocator> 1802 template <class _Tp, class _Allocator>
1803 typename vector<_Tp, _Allocator>::iterator 1803 typename vector<_Tp, _Allocator>::iterator
1804 vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x) 1804 vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x)
1805 { 1805 {
1806 #if _LIBCPP_DEBUG_LEVEL >= 2 1806 #if _LIBCPP_DEBUG_LEVEL == 2
1807 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, 1807 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1808 "vector::insert(iterator, x) called with an iterator not" 1808 "vector::insert(iterator, x) called with an iterator not"
1809 " referring to this vector"); 1809 " referring to this vector");
1810 #endif 1810 #endif
1811 pointer __p = this->__begin_ + (__position - begin()); 1811 pointer __p = this->__begin_ + (__position - begin());
1834 template <class _Tp, class _Allocator> 1834 template <class _Tp, class _Allocator>
1835 template <class... _Args> 1835 template <class... _Args>
1836 typename vector<_Tp, _Allocator>::iterator 1836 typename vector<_Tp, _Allocator>::iterator
1837 vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args) 1837 vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args)
1838 { 1838 {
1839 #if _LIBCPP_DEBUG_LEVEL >= 2 1839 #if _LIBCPP_DEBUG_LEVEL == 2
1840 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, 1840 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1841 "vector::emplace(iterator, x) called with an iterator not" 1841 "vector::emplace(iterator, x) called with an iterator not"
1842 " referring to this vector"); 1842 " referring to this vector");
1843 #endif 1843 #endif
1844 pointer __p = this->__begin_ + (__position - begin()); 1844 pointer __p = this->__begin_ + (__position - begin());
1863 __p = __swap_out_circular_buffer(__v, __p); 1863 __p = __swap_out_circular_buffer(__v, __p);
1864 } 1864 }
1865 return __make_iter(__p); 1865 return __make_iter(__p);
1866 } 1866 }
1867 1867
1868 #endif // !_LIBCPP_CXX03_LANG 1868 #endif // !_LIBCPP_CXX03_LANG
1869 1869
1870 template <class _Tp, class _Allocator> 1870 template <class _Tp, class _Allocator>
1871 typename vector<_Tp, _Allocator>::iterator 1871 typename vector<_Tp, _Allocator>::iterator
1872 vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x) 1872 vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x)
1873 { 1873 {
1874 #if _LIBCPP_DEBUG_LEVEL >= 2 1874 #if _LIBCPP_DEBUG_LEVEL == 2
1875 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, 1875 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1876 "vector::insert(iterator, n, x) called with an iterator not" 1876 "vector::insert(iterator, n, x) called with an iterator not"
1877 " referring to this vector"); 1877 " referring to this vector");
1878 #endif 1878 #endif
1879 pointer __p = this->__begin_ + (__position - begin()); 1879 pointer __p = this->__begin_ + (__position - begin());
1920 typename iterator_traits<_InputIterator>::reference>::value, 1920 typename iterator_traits<_InputIterator>::reference>::value,
1921 typename vector<_Tp, _Allocator>::iterator 1921 typename vector<_Tp, _Allocator>::iterator
1922 >::type 1922 >::type
1923 vector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last) 1923 vector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
1924 { 1924 {
1925 #if _LIBCPP_DEBUG_LEVEL >= 2 1925 #if _LIBCPP_DEBUG_LEVEL == 2
1926 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, 1926 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1927 "vector::insert(iterator, range) called with an iterator not" 1927 "vector::insert(iterator, range) called with an iterator not"
1928 " referring to this vector"); 1928 " referring to this vector");
1929 #endif 1929 #endif
1930 difference_type __off = __position - begin(); 1930 difference_type __off = __position - begin();
1939 if (__first != __last) 1939 if (__first != __last)
1940 { 1940 {
1941 #ifndef _LIBCPP_NO_EXCEPTIONS 1941 #ifndef _LIBCPP_NO_EXCEPTIONS
1942 try 1942 try
1943 { 1943 {
1944 #endif // _LIBCPP_NO_EXCEPTIONS 1944 #endif // _LIBCPP_NO_EXCEPTIONS
1945 __v.__construct_at_end(__first, __last); 1945 __v.__construct_at_end(__first, __last);
1946 difference_type __old_size = __old_last - this->__begin_; 1946 difference_type __old_size = __old_last - this->__begin_;
1947 difference_type __old_p = __p - this->__begin_; 1947 difference_type __old_p = __p - this->__begin_;
1948 reserve(__recommend(size() + __v.size())); 1948 reserve(__recommend(size() + __v.size()));
1949 __p = this->__begin_ + __old_p; 1949 __p = this->__begin_ + __old_p;
1953 catch (...) 1953 catch (...)
1954 { 1954 {
1955 erase(__make_iter(__old_last), end()); 1955 erase(__make_iter(__old_last), end());
1956 throw; 1956 throw;
1957 } 1957 }
1958 #endif // _LIBCPP_NO_EXCEPTIONS 1958 #endif // _LIBCPP_NO_EXCEPTIONS
1959 } 1959 }
1960 __p = _VSTD::rotate(__p, __old_last, this->__end_); 1960 __p = _VSTD::rotate(__p, __old_last, this->__end_);
1961 insert(__make_iter(__p), _VSTD::make_move_iterator(__v.begin()), 1961 insert(__make_iter(__p), _VSTD::make_move_iterator(__v.begin()),
1962 _VSTD::make_move_iterator(__v.end())); 1962 _VSTD::make_move_iterator(__v.end()));
1963 return begin() + __off; 1963 return begin() + __off;
1973 typename iterator_traits<_ForwardIterator>::reference>::value, 1973 typename iterator_traits<_ForwardIterator>::reference>::value,
1974 typename vector<_Tp, _Allocator>::iterator 1974 typename vector<_Tp, _Allocator>::iterator
1975 >::type 1975 >::type
1976 vector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last) 1976 vector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
1977 { 1977 {
1978 #if _LIBCPP_DEBUG_LEVEL >= 2 1978 #if _LIBCPP_DEBUG_LEVEL == 2
1979 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, 1979 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1980 "vector::insert(iterator, range) called with an iterator not" 1980 "vector::insert(iterator, range) called with an iterator not"
1981 " referring to this vector"); 1981 " referring to this vector");
1982 #endif 1982 #endif
1983 pointer __p = this->__begin_ + (__position - begin()); 1983 pointer __p = this->__begin_ + (__position - begin());
2052 "vector::swap: Either propagate_on_container_swap must be true" 2052 "vector::swap: Either propagate_on_container_swap must be true"
2053 " or the allocators must compare equal"); 2053 " or the allocators must compare equal");
2054 _VSTD::swap(this->__begin_, __x.__begin_); 2054 _VSTD::swap(this->__begin_, __x.__begin_);
2055 _VSTD::swap(this->__end_, __x.__end_); 2055 _VSTD::swap(this->__end_, __x.__end_);
2056 _VSTD::swap(this->__end_cap(), __x.__end_cap()); 2056 _VSTD::swap(this->__end_cap(), __x.__end_cap());
2057 __swap_allocator(this->__alloc(), __x.__alloc(), 2057 _VSTD::__swap_allocator(this->__alloc(), __x.__alloc(),
2058 integral_constant<bool,__alloc_traits::propagate_on_container_swap::value>()); 2058 integral_constant<bool,__alloc_traits::propagate_on_container_swap::value>());
2059 #if _LIBCPP_DEBUG_LEVEL >= 2 2059 #if _LIBCPP_DEBUG_LEVEL == 2
2060 __get_db()->swap(this, &__x); 2060 __get_db()->swap(this, &__x);
2061 #endif // _LIBCPP_DEBUG_LEVEL >= 2 2061 #endif
2062 } 2062 }
2063 2063
2064 template <class _Tp, class _Allocator> 2064 template <class _Tp, class _Allocator>
2065 bool 2065 bool
2066 vector<_Tp, _Allocator>::__invariants() const 2066 vector<_Tp, _Allocator>::__invariants() const
2080 return false; 2080 return false;
2081 } 2081 }
2082 return true; 2082 return true;
2083 } 2083 }
2084 2084
2085 #if _LIBCPP_DEBUG_LEVEL >= 2 2085 #if _LIBCPP_DEBUG_LEVEL == 2
2086 2086
2087 template <class _Tp, class _Allocator> 2087 template <class _Tp, class _Allocator>
2088 bool 2088 bool
2089 vector<_Tp, _Allocator>::__dereferenceable(const const_iterator* __i) const 2089 vector<_Tp, _Allocator>::__dereferenceable(const const_iterator* __i) const
2090 { 2090 {
2112 { 2112 {
2113 const_pointer __p = __i->base() + __n; 2113 const_pointer __p = __i->base() + __n;
2114 return this->__begin_ <= __p && __p < this->__end_; 2114 return this->__begin_ <= __p && __p < this->__end_;
2115 } 2115 }
2116 2116
2117 #endif // _LIBCPP_DEBUG_LEVEL >= 2 2117 #endif // _LIBCPP_DEBUG_LEVEL == 2
2118 2118
2119 template <class _Tp, class _Allocator> 2119 template <class _Tp, class _Allocator>
2120 inline _LIBCPP_INLINE_VISIBILITY 2120 inline _LIBCPP_INLINE_VISIBILITY
2121 void 2121 void
2122 vector<_Tp, _Allocator>::__invalidate_all_iterators() 2122 vector<_Tp, _Allocator>::__invalidate_all_iterators()
2123 { 2123 {
2124 #if _LIBCPP_DEBUG_LEVEL >= 2 2124 #if _LIBCPP_DEBUG_LEVEL == 2
2125 __get_db()->__invalidate_all(this); 2125 __get_db()->__invalidate_all(this);
2126 #endif // _LIBCPP_DEBUG_LEVEL >= 2 2126 #endif
2127 } 2127 }
2128 2128
2129 2129
2130 template <class _Tp, class _Allocator> 2130 template <class _Tp, class _Allocator>
2131 inline _LIBCPP_INLINE_VISIBILITY 2131 inline _LIBCPP_INLINE_VISIBILITY
2132 void 2132 void
2133 vector<_Tp, _Allocator>::__invalidate_iterators_past(pointer __new_last) { 2133 vector<_Tp, _Allocator>::__invalidate_iterators_past(pointer __new_last) {
2134 #if _LIBCPP_DEBUG_LEVEL >= 2 2134 #if _LIBCPP_DEBUG_LEVEL == 2
2135 __c_node* __c = __get_db()->__find_c_and_lock(this); 2135 __c_node* __c = __get_db()->__find_c_and_lock(this);
2136 for (__i_node** __p = __c->end_; __p != __c->beg_; ) { 2136 for (__i_node** __p = __c->end_; __p != __c->beg_; ) {
2137 --__p; 2137 --__p;
2138 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_); 2138 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
2139 if (__i->base() > __new_last) { 2139 if (__i->base() > __new_last) {
2140 (*__p)->__c_ = nullptr; 2140 (*__p)->__c_ = nullptr;
2141 if (--__c->end_ != __p) 2141 if (--__c->end_ != __p)
2142 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); 2142 _VSTD::memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
2143 } 2143 }
2144 } 2144 }
2145 __get_db()->unlock(); 2145 __get_db()->unlock();
2146 #else 2146 #else
2147 ((void)__new_last); 2147 ((void)__new_last);
2268 2268
2269 _LIBCPP_INLINE_VISIBILITY 2269 _LIBCPP_INLINE_VISIBILITY
2270 vector& operator=(initializer_list<value_type> __il) 2270 vector& operator=(initializer_list<value_type> __il)
2271 {assign(__il.begin(), __il.end()); return *this;} 2271 {assign(__il.begin(), __il.end()); return *this;}
2272 2272
2273 #endif // !_LIBCPP_CXX03_LANG 2273 #endif // !_LIBCPP_CXX03_LANG
2274 2274
2275 template <class _InputIterator> 2275 template <class _InputIterator>
2276 typename enable_if 2276 typename enable_if
2277 < 2277 <
2278 __is_cpp17_input_iterator<_InputIterator>::value && 2278 __is_cpp17_input_iterator<_InputIterator>::value &&
2706 __cap_alloc_(0, __default_init_tag()) 2706 __cap_alloc_(0, __default_init_tag())
2707 { 2707 {
2708 #ifndef _LIBCPP_NO_EXCEPTIONS 2708 #ifndef _LIBCPP_NO_EXCEPTIONS
2709 try 2709 try
2710 { 2710 {
2711 #endif // _LIBCPP_NO_EXCEPTIONS 2711 #endif // _LIBCPP_NO_EXCEPTIONS
2712 for (; __first != __last; ++__first) 2712 for (; __first != __last; ++__first)
2713 push_back(*__first); 2713 push_back(*__first);
2714 #ifndef _LIBCPP_NO_EXCEPTIONS 2714 #ifndef _LIBCPP_NO_EXCEPTIONS
2715 } 2715 }
2716 catch (...) 2716 catch (...)
2718 if (__begin_ != nullptr) 2718 if (__begin_ != nullptr)
2719 __storage_traits::deallocate(__alloc(), __begin_, __cap()); 2719 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2720 __invalidate_all_iterators(); 2720 __invalidate_all_iterators();
2721 throw; 2721 throw;
2722 } 2722 }
2723 #endif // _LIBCPP_NO_EXCEPTIONS 2723 #endif // _LIBCPP_NO_EXCEPTIONS
2724 } 2724 }
2725 2725
2726 template <class _Allocator> 2726 template <class _Allocator>
2727 template <class _InputIterator> 2727 template <class _InputIterator>
2728 vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, 2728 vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2733 __cap_alloc_(0, static_cast<__storage_allocator>(__a)) 2733 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2734 { 2734 {
2735 #ifndef _LIBCPP_NO_EXCEPTIONS 2735 #ifndef _LIBCPP_NO_EXCEPTIONS
2736 try 2736 try
2737 { 2737 {
2738 #endif // _LIBCPP_NO_EXCEPTIONS 2738 #endif // _LIBCPP_NO_EXCEPTIONS
2739 for (; __first != __last; ++__first) 2739 for (; __first != __last; ++__first)
2740 push_back(*__first); 2740 push_back(*__first);
2741 #ifndef _LIBCPP_NO_EXCEPTIONS 2741 #ifndef _LIBCPP_NO_EXCEPTIONS
2742 } 2742 }
2743 catch (...) 2743 catch (...)
2745 if (__begin_ != nullptr) 2745 if (__begin_ != nullptr)
2746 __storage_traits::deallocate(__alloc(), __begin_, __cap()); 2746 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2747 __invalidate_all_iterators(); 2747 __invalidate_all_iterators();
2748 throw; 2748 throw;
2749 } 2749 }
2750 #endif // _LIBCPP_NO_EXCEPTIONS 2750 #endif // _LIBCPP_NO_EXCEPTIONS
2751 } 2751 }
2752 2752
2753 template <class _Allocator> 2753 template <class _Allocator>
2754 template <class _ForwardIterator> 2754 template <class _ForwardIterator>
2755 vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, 2755 vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last,
2810 __vallocate(__n); 2810 __vallocate(__n);
2811 __construct_at_end(__il.begin(), __il.end()); 2811 __construct_at_end(__il.begin(), __il.end());
2812 } 2812 }
2813 } 2813 }
2814 2814
2815 #endif // _LIBCPP_CXX03_LANG 2815 #endif // _LIBCPP_CXX03_LANG
2816 2816
2817 template <class _Allocator> 2817 template <class _Allocator>
2818 vector<bool, _Allocator>::~vector() 2818 vector<bool, _Allocator>::~vector()
2819 { 2819 {
2820 if (__begin_ != nullptr) 2820 if (__begin_ != nullptr)
2878 #else 2878 #else
2879 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) 2879 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
2880 #endif 2880 #endif
2881 : __begin_(__v.__begin_), 2881 : __begin_(__v.__begin_),
2882 __size_(__v.__size_), 2882 __size_(__v.__size_),
2883 __cap_alloc_(std::move(__v.__cap_alloc_)) { 2883 __cap_alloc_(_VSTD::move(__v.__cap_alloc_)) {
2884 __v.__begin_ = nullptr; 2884 __v.__begin_ = nullptr;
2885 __v.__size_ = 0; 2885 __v.__size_ = 0;
2886 __v.__cap() = 0; 2886 __v.__cap() = 0;
2887 } 2887 }
2888 2888
2940 this->__cap() = __c.__cap(); 2940 this->__cap() = __c.__cap();
2941 __c.__begin_ = nullptr; 2941 __c.__begin_ = nullptr;
2942 __c.__cap() = __c.__size_ = 0; 2942 __c.__cap() = __c.__size_ = 0;
2943 } 2943 }
2944 2944
2945 #endif // !_LIBCPP_CXX03_LANG 2945 #endif // !_LIBCPP_CXX03_LANG
2946 2946
2947 template <class _Allocator> 2947 template <class _Allocator>
2948 void 2948 void
2949 vector<bool, _Allocator>::assign(size_type __n, const value_type& __x) 2949 vector<bool, _Allocator>::assign(size_type __n, const value_type& __x)
2950 { 2950 {
3026 if (__external_cap_to_internal(size()) > __cap()) 3026 if (__external_cap_to_internal(size()) > __cap())
3027 { 3027 {
3028 #ifndef _LIBCPP_NO_EXCEPTIONS 3028 #ifndef _LIBCPP_NO_EXCEPTIONS
3029 try 3029 try
3030 { 3030 {
3031 #endif // _LIBCPP_NO_EXCEPTIONS 3031 #endif // _LIBCPP_NO_EXCEPTIONS
3032 vector(*this, allocator_type(__alloc())).swap(*this); 3032 vector(*this, allocator_type(__alloc())).swap(*this);
3033 #ifndef _LIBCPP_NO_EXCEPTIONS 3033 #ifndef _LIBCPP_NO_EXCEPTIONS
3034 } 3034 }
3035 catch (...) 3035 catch (...)
3036 { 3036 {
3037 } 3037 }
3038 #endif // _LIBCPP_NO_EXCEPTIONS 3038 #endif // _LIBCPP_NO_EXCEPTIONS
3039 } 3039 }
3040 } 3040 }
3041 3041
3042 template <class _Allocator> 3042 template <class _Allocator>
3043 typename vector<bool, _Allocator>::reference 3043 typename vector<bool, _Allocator>::reference
3140 if (__first != __last) 3140 if (__first != __last)
3141 { 3141 {
3142 #ifndef _LIBCPP_NO_EXCEPTIONS 3142 #ifndef _LIBCPP_NO_EXCEPTIONS
3143 try 3143 try
3144 { 3144 {
3145 #endif // _LIBCPP_NO_EXCEPTIONS 3145 #endif // _LIBCPP_NO_EXCEPTIONS
3146 __v.assign(__first, __last); 3146 __v.assign(__first, __last);
3147 difference_type __old_size = static_cast<difference_type>(__old_end - begin()); 3147 difference_type __old_size = static_cast<difference_type>(__old_end - begin());
3148 difference_type __old_p = __p - begin(); 3148 difference_type __old_p = __p - begin();
3149 reserve(__recommend(size() + __v.size())); 3149 reserve(__recommend(size() + __v.size()));
3150 __p = begin() + __old_p; 3150 __p = begin() + __old_p;
3154 catch (...) 3154 catch (...)
3155 { 3155 {
3156 erase(__old_end, end()); 3156 erase(__old_end, end());
3157 throw; 3157 throw;
3158 } 3158 }
3159 #endif // _LIBCPP_NO_EXCEPTIONS 3159 #endif // _LIBCPP_NO_EXCEPTIONS
3160 } 3160 }
3161 __p = _VSTD::rotate(__p, __old_end, end()); 3161 __p = _VSTD::rotate(__p, __old_end, end());
3162 insert(__p, __v.begin(), __v.end()); 3162 insert(__p, __v.begin(), __v.end());
3163 return begin() + __off; 3163 return begin() + __off;
3164 } 3164 }
3230 #endif 3230 #endif
3231 { 3231 {
3232 _VSTD::swap(this->__begin_, __x.__begin_); 3232 _VSTD::swap(this->__begin_, __x.__begin_);
3233 _VSTD::swap(this->__size_, __x.__size_); 3233 _VSTD::swap(this->__size_, __x.__size_);
3234 _VSTD::swap(this->__cap(), __x.__cap()); 3234 _VSTD::swap(this->__cap(), __x.__cap());
3235 __swap_allocator(this->__alloc(), __x.__alloc(), 3235 _VSTD::__swap_allocator(this->__alloc(), __x.__alloc(),
3236 integral_constant<bool, __alloc_traits::propagate_on_container_swap::value>()); 3236 integral_constant<bool, __alloc_traits::propagate_on_container_swap::value>());
3237 } 3237 }
3238 3238
3239 template <class _Allocator> 3239 template <class _Allocator>
3240 void 3240 void
3409 3409
3410 _LIBCPP_END_NAMESPACE_STD 3410 _LIBCPP_END_NAMESPACE_STD
3411 3411
3412 _LIBCPP_POP_MACROS 3412 _LIBCPP_POP_MACROS
3413 3413
3414 #endif // _LIBCPP_VECTOR 3414 #endif // _LIBCPP_VECTOR