diff options
Diffstat (limited to 'system/include/libcxx/vector')
-rw-r--r-- | system/include/libcxx/vector | 109 |
1 files changed, 52 insertions, 57 deletions
diff --git a/system/include/libcxx/vector b/system/include/libcxx/vector index d1bc23e6..0758f75b 100644 --- a/system/include/libcxx/vector +++ b/system/include/libcxx/vector @@ -272,6 +272,12 @@ void swap(vector<T,Allocator>& x, vector<T,Allocator>& y) #include <__undef_min_max> +#ifdef _LIBCPP_DEBUG2 +# include <__debug> +#else +# define _LIBCPP_ASSERT(x, m) ((void)0) +#endif + #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif @@ -309,14 +315,14 @@ __vector_base_common<__b>::__throw_out_of_range() const #endif } -#ifdef _MSC_VER +#ifdef _LIBCPP_MSVC #pragma warning( push ) #pragma warning( disable: 4231 ) -#endif // _MSC_VER +#endif // _LIBCPP_MSVC _LIBCPP_EXTERN_TEMPLATE(class __vector_base_common<true>) -#ifdef _MSC_VER +#ifdef _LIBCPP_MSVC #pragma warning( pop ) -#endif // _MSC_VER +#endif // _LIBCPP_MSVC template <class _Tp, class _Allocator> class __vector_base @@ -365,12 +371,7 @@ protected: {return static_cast<size_type>(__end_cap() - __begin_);} _LIBCPP_INLINE_VISIBILITY - void __destruct_at_end(const_pointer __new_last) _NOEXCEPT - {__destruct_at_end(__new_last, false_type());} - _LIBCPP_INLINE_VISIBILITY - void __destruct_at_end(const_pointer __new_last, false_type) _NOEXCEPT; - _LIBCPP_INLINE_VISIBILITY - void __destruct_at_end(const_pointer __new_last, true_type) _NOEXCEPT; + void __destruct_at_end(pointer __new_last) _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY void __copy_assign_alloc(const __vector_base& __c) @@ -437,43 +438,35 @@ private: template <class _Tp, class _Allocator> _LIBCPP_INLINE_VISIBILITY inline void -__vector_base<_Tp, _Allocator>::__destruct_at_end(const_pointer __new_last, false_type) _NOEXCEPT +__vector_base<_Tp, _Allocator>::__destruct_at_end(pointer __new_last) _NOEXCEPT { while (__new_last != __end_) - __alloc_traits::destroy(__alloc(), const_cast<pointer>(--__end_)); -} - -template <class _Tp, class _Allocator> -_LIBCPP_INLINE_VISIBILITY inline -void -__vector_base<_Tp, _Allocator>::__destruct_at_end(const_pointer __new_last, true_type) _NOEXCEPT -{ - __end_ = const_cast<pointer>(__new_last); + __alloc_traits::destroy(__alloc(), _VSTD::__to_raw_pointer(--__end_)); } template <class _Tp, class _Allocator> _LIBCPP_INLINE_VISIBILITY inline __vector_base<_Tp, _Allocator>::__vector_base() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) - : __begin_(0), - __end_(0), - __end_cap_(0) + : __begin_(nullptr), + __end_(nullptr), + __end_cap_(nullptr) { } template <class _Tp, class _Allocator> _LIBCPP_INLINE_VISIBILITY inline __vector_base<_Tp, _Allocator>::__vector_base(const allocator_type& __a) - : __begin_(0), - __end_(0), - __end_cap_(0, __a) + : __begin_(nullptr), + __end_(nullptr), + __end_cap_(nullptr, __a) { } template <class _Tp, class _Allocator> __vector_base<_Tp, _Allocator>::~__vector_base() { - if (__begin_ != 0) + if (__begin_ != nullptr) { clear(); __alloc_traits::deallocate(__alloc(), __begin_, capacity()); @@ -797,7 +790,7 @@ private: _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); void __move_assign(vector& __c, false_type); _LIBCPP_INLINE_VISIBILITY - void __destruct_at_end(const_pointer __new_last) _NOEXCEPT + void __destruct_at_end(pointer __new_last) _NOEXCEPT { #if _LIBCPP_DEBUG_LEVEL >= 2 __c_node* __c = __get_db()->__find_c_and_lock(this); @@ -878,11 +871,11 @@ template <class _Tp, class _Allocator> void vector<_Tp, _Allocator>::deallocate() _NOEXCEPT { - if (this->__begin_ != 0) + if (this->__begin_ != nullptr) { clear(); __alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity()); - this->__begin_ = this->__end_ = this->__end_cap() = 0; + this->__begin_ = this->__end_ = this->__end_cap() = nullptr; } } @@ -1171,7 +1164,7 @@ vector<_Tp, _Allocator>::vector(vector&& __x) this->__begin_ = __x.__begin_; this->__end_ = __x.__end_; this->__end_cap() = __x.__end_cap(); - __x.__begin_ = __x.__end_ = __x.__end_cap() = 0; + __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr; } template <class _Tp, class _Allocator> @@ -1597,7 +1590,8 @@ vector<_Tp, _Allocator>::erase(const_iterator __position) #endif _LIBCPP_ASSERT(__position != end(), "vector::erase(iterator) called with a non-dereferenceable iterator"); - pointer __p = const_cast<pointer>(&*__position); + difference_type __ps = __position - cbegin(); + pointer __p = this->__begin_ + __ps; iterator __r = __make_iter(__p); this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p)); return __r; @@ -1615,7 +1609,8 @@ vector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last) _LIBCPP_ASSERT(__first <= __last, "vector::erase(first, last) called with invalid range"); pointer __p = this->__begin_ + (__first - begin()); iterator __r = __make_iter(__p); - this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p)); + if (__first != __last) + this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p)); return __r; } @@ -1942,9 +1937,9 @@ template <class _Tp, class _Allocator> bool vector<_Tp, _Allocator>::__invariants() const { - if (this->__begin_ == 0) + if (this->__begin_ == nullptr) { - if (this->__end_ != 0 || this->__end_cap() != 0) + if (this->__end_ != nullptr || this->__end_cap() != nullptr) return false; } else @@ -2306,7 +2301,7 @@ private: {return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));} _LIBCPP_INLINE_VISIBILITY iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT - {return iterator(const_cast<__storage_pointer>(__p.__seg_), __p.__ctz_);} + {return begin() + (__p - cbegin());} #endif // _LIBCPP_DEBUG _LIBCPP_INLINE_VISIBILITY @@ -2413,11 +2408,11 @@ template <class _Allocator> void vector<bool, _Allocator>::deallocate() _NOEXCEPT { - if (this->__begin_ != 0) + if (this->__begin_ != nullptr) { __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap()); __invalidate_all_iterators(); - this->__begin_ = 0; + this->__begin_ = nullptr; this->__size_ = this->__cap() = 0; } } @@ -2480,7 +2475,7 @@ template <class _Allocator> _LIBCPP_INLINE_VISIBILITY inline vector<bool, _Allocator>::vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) - : __begin_(0), + : __begin_(nullptr), __size_(0), __cap_alloc_(0) { @@ -2489,7 +2484,7 @@ vector<bool, _Allocator>::vector() template <class _Allocator> _LIBCPP_INLINE_VISIBILITY inline vector<bool, _Allocator>::vector(const allocator_type& __a) - : __begin_(0), + : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) { @@ -2497,7 +2492,7 @@ vector<bool, _Allocator>::vector(const allocator_type& __a) template <class _Allocator> vector<bool, _Allocator>::vector(size_type __n) - : __begin_(0), + : __begin_(nullptr), __size_(0), __cap_alloc_(0) { @@ -2510,7 +2505,7 @@ vector<bool, _Allocator>::vector(size_type __n) template <class _Allocator> vector<bool, _Allocator>::vector(size_type __n, const value_type& __x) - : __begin_(0), + : __begin_(nullptr), __size_(0), __cap_alloc_(0) { @@ -2523,7 +2518,7 @@ vector<bool, _Allocator>::vector(size_type __n, const value_type& __x) template <class _Allocator> vector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a) - : __begin_(0), + : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) { @@ -2539,7 +2534,7 @@ template <class _InputIterator> vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, typename enable_if<__is_input_iterator <_InputIterator>::value && !__is_forward_iterator<_InputIterator>::value>::type*) - : __begin_(0), + : __begin_(nullptr), __size_(0), __cap_alloc_(0) { @@ -2553,7 +2548,7 @@ vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, } catch (...) { - if (__begin_ != 0) + if (__begin_ != nullptr) __storage_traits::deallocate(__alloc(), __begin_, __cap()); __invalidate_all_iterators(); throw; @@ -2566,7 +2561,7 @@ template <class _InputIterator> vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, typename enable_if<__is_input_iterator <_InputIterator>::value && !__is_forward_iterator<_InputIterator>::value>::type*) - : __begin_(0), + : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) { @@ -2580,7 +2575,7 @@ vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, } catch (...) { - if (__begin_ != 0) + if (__begin_ != nullptr) __storage_traits::deallocate(__alloc(), __begin_, __cap()); __invalidate_all_iterators(); throw; @@ -2592,7 +2587,7 @@ template <class _Allocator> template <class _ForwardIterator> vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*) - : __begin_(0), + : __begin_(nullptr), __size_(0), __cap_alloc_(0) { @@ -2608,7 +2603,7 @@ template <class _Allocator> template <class _ForwardIterator> vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*) - : __begin_(0), + : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) { @@ -2624,7 +2619,7 @@ vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __la template <class _Allocator> vector<bool, _Allocator>::vector(initializer_list<value_type> __il) - : __begin_(0), + : __begin_(nullptr), __size_(0), __cap_alloc_(0) { @@ -2638,7 +2633,7 @@ vector<bool, _Allocator>::vector(initializer_list<value_type> __il) template <class _Allocator> vector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a) - : __begin_(0), + : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) { @@ -2655,7 +2650,7 @@ vector<bool, _Allocator>::vector(initializer_list<value_type> __il, const alloca template <class _Allocator> vector<bool, _Allocator>::~vector() { - if (__begin_ != 0) + if (__begin_ != nullptr) __storage_traits::deallocate(__alloc(), __begin_, __cap()); #ifdef _LIBCPP_DEBUG __invalidate_all_iterators(); @@ -2664,7 +2659,7 @@ vector<bool, _Allocator>::~vector() template <class _Allocator> vector<bool, _Allocator>::vector(const vector& __v) - : __begin_(0), + : __begin_(nullptr), __size_(0), __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc())) { @@ -2677,7 +2672,7 @@ vector<bool, _Allocator>::vector(const vector& __v) template <class _Allocator> vector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a) - : __begin_(0), + : __begin_(nullptr), __size_(0), __cap_alloc_(0, __a) { @@ -2719,14 +2714,14 @@ vector<bool, _Allocator>::vector(vector&& __v) __size_(__v.__size_), __cap_alloc_(__v.__cap_alloc_) { - __v.__begin_ = 0; + __v.__begin_ = nullptr; __v.__size_ = 0; __v.__cap() = 0; } template <class _Allocator> vector<bool, _Allocator>::vector(vector&& __v, const allocator_type& __a) - : __begin_(0), + : __begin_(nullptr), __size_(0), __cap_alloc_(0, __a) { @@ -3122,7 +3117,7 @@ template <class _Allocator> bool vector<bool, _Allocator>::__invariants() const { - if (this->__begin_ == 0) + if (this->__begin_ == nullptr) { if (this->__size_ != 0 || this->__cap() != 0) return false; |