Implement full support for non-pointer pointers in custom allocators for vector.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@185093 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -365,12 +365,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 +432,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 +784,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 +865,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 +1158,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 +1584,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;
|
||||
@@ -1943,9 +1931,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
|
||||
@@ -2307,7 +2295,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
|
||||
@@ -2414,11 +2402,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;
|
||||
}
|
||||
}
|
||||
@@ -2481,7 +2469,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)
|
||||
{
|
||||
@@ -2490,7 +2478,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))
|
||||
{
|
||||
@@ -2498,7 +2486,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)
|
||||
{
|
||||
@@ -2511,7 +2499,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)
|
||||
{
|
||||
@@ -2524,7 +2512,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))
|
||||
{
|
||||
@@ -2540,7 +2528,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)
|
||||
{
|
||||
@@ -2554,7 +2542,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;
|
||||
@@ -2567,7 +2555,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))
|
||||
{
|
||||
@@ -2581,7 +2569,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;
|
||||
@@ -2593,7 +2581,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)
|
||||
{
|
||||
@@ -2609,7 +2597,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))
|
||||
{
|
||||
@@ -2625,7 +2613,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)
|
||||
{
|
||||
@@ -2639,7 +2627,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))
|
||||
{
|
||||
@@ -2656,7 +2644,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();
|
||||
@@ -2665,7 +2653,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()))
|
||||
{
|
||||
@@ -2678,7 +2666,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)
|
||||
{
|
||||
@@ -2720,14 +2708,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)
|
||||
{
|
||||
@@ -3123,7 +3111,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;
|
||||
|
Reference in New Issue
Block a user