aboutsummaryrefslogtreecommitdiff
path: root/libcxx/include/vector
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2021-11-19 20:06:13 +0000
committerDimitry Andric <dim@FreeBSD.org>2021-11-19 20:06:13 +0000
commitc0981da47d5696fe36474fcf86b4ce03ae3ff818 (patch)
treef42add1021b9f2ac6a69ac7cf6c4499962739a45 /libcxx/include/vector
parent344a3780b2e33f6ca763666c380202b18aab72a3 (diff)
downloadsrc-c0981da47d5696fe36474fcf86b4ce03ae3ff818.tar.gz
src-c0981da47d5696fe36474fcf86b4ce03ae3ff818.zip
Diffstat (limited to 'libcxx/include/vector')
-rw-r--r--libcxx/include/vector391
1 files changed, 181 insertions, 210 deletions
diff --git a/libcxx/include/vector b/libcxx/include/vector
index 9189ed44a80c..e41afbaca509 100644
--- a/libcxx/include/vector
+++ b/libcxx/include/vector
@@ -1,5 +1,5 @@
// -*- C++ -*-
-//===------------------------------ vector --------------------------------===//
+//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -245,7 +245,7 @@ public:
template <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
vector(InputIterator, InputIterator, Allocator = Allocator())
- -> vector<typename iterator_traits<InputIterator>::value_type, Allocator>;
+ -> vector<typename iterator_traits<InputIterator>::value_type, Allocator>; // C++17
template <class Allocator> struct hash<std::vector<bool, Allocator>>;
@@ -275,12 +275,14 @@ erase_if(vector<T, Allocator>& c, Predicate pred); // C++20
#include <__bit_reference>
#include <__debug>
#include <__functional_base>
+#include <__iterator/iterator_traits.h>
#include <__iterator/wrap_iter.h>
#include <__split_buffer>
#include <__utility/forward.h>
#include <algorithm>
#include <climits>
#include <compare>
+#include <cstdlib>
#include <cstring>
#include <initializer_list>
#include <iosfwd> // for forward declaration of vector
@@ -301,196 +303,70 @@ _LIBCPP_PUSH_MACROS
_LIBCPP_BEGIN_NAMESPACE_STD
template <bool>
-class _LIBCPP_TEMPLATE_VIS __vector_base_common
-{
-protected:
- _LIBCPP_INLINE_VISIBILITY __vector_base_common() {}
- _LIBCPP_NORETURN void __throw_length_error() const;
- _LIBCPP_NORETURN void __throw_out_of_range() const;
-};
-
-template <bool __b>
-void
-__vector_base_common<__b>::__throw_length_error() const
-{
- _VSTD::__throw_length_error("vector");
-}
-
-template <bool __b>
-void
-__vector_base_common<__b>::__throw_out_of_range() const
-{
- _VSTD::__throw_out_of_range("vector");
-}
+struct __vector_base_common;
-_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __vector_base_common<true>)
+template <>
+struct __vector_base_common<true> {
+ // Both are defined in vector.cpp
+ _LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void __throw_length_error() const;
+ _LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void __throw_out_of_range() const;
+};
template <class _Tp, class _Allocator>
class __vector_base
- : protected __vector_base_common<true>
+ : protected __vector_base_common<true> // This base class is historical, but it needs to remain for ABI compatibility
{
-public:
- typedef _Allocator allocator_type;
- typedef allocator_traits<allocator_type> __alloc_traits;
- typedef typename __alloc_traits::size_type size_type;
-protected:
- typedef _Tp value_type;
- typedef value_type& reference;
- typedef const value_type& const_reference;
- typedef typename __alloc_traits::difference_type difference_type;
- typedef typename __alloc_traits::pointer pointer;
- typedef typename __alloc_traits::const_pointer const_pointer;
- typedef pointer iterator;
- typedef const_pointer const_iterator;
+ typedef _Allocator allocator_type;
+ typedef typename allocator_traits<allocator_type>::pointer pointer;
- pointer __begin_;
- pointer __end_;
- __compressed_pair<pointer, allocator_type> __end_cap_;
-
- _LIBCPP_INLINE_VISIBILITY
- allocator_type& __alloc() _NOEXCEPT
- {return __end_cap_.second();}
- _LIBCPP_INLINE_VISIBILITY
- const allocator_type& __alloc() const _NOEXCEPT
- {return __end_cap_.second();}
- _LIBCPP_INLINE_VISIBILITY
- pointer& __end_cap() _NOEXCEPT
- {return __end_cap_.first();}
- _LIBCPP_INLINE_VISIBILITY
- const pointer& __end_cap() const _NOEXCEPT
- {return __end_cap_.first();}
+protected:
+ pointer __begin_;
+ pointer __end_;
+ __compressed_pair<pointer, allocator_type> __end_cap_;
_LIBCPP_INLINE_VISIBILITY
__vector_base()
- _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
- _LIBCPP_INLINE_VISIBILITY __vector_base(const allocator_type& __a);
-#ifndef _LIBCPP_CXX03_LANG
- _LIBCPP_INLINE_VISIBILITY __vector_base(allocator_type&& __a) _NOEXCEPT;
-#endif
- ~__vector_base();
-
- _LIBCPP_INLINE_VISIBILITY
- void clear() _NOEXCEPT {__destruct_at_end(__begin_);}
- _LIBCPP_INLINE_VISIBILITY
- size_type capacity() const _NOEXCEPT
- {return static_cast<size_type>(__end_cap() - __begin_);}
-
- _LIBCPP_INLINE_VISIBILITY
- void __destruct_at_end(pointer __new_last) _NOEXCEPT;
-
- _LIBCPP_INLINE_VISIBILITY
- void __copy_assign_alloc(const __vector_base& __c)
- {__copy_assign_alloc(__c, integral_constant<bool,
- __alloc_traits::propagate_on_container_copy_assignment::value>());}
-
- _LIBCPP_INLINE_VISIBILITY
- void __move_assign_alloc(__vector_base& __c)
- _NOEXCEPT_(
- !__alloc_traits::propagate_on_container_move_assignment::value ||
- is_nothrow_move_assignable<allocator_type>::value)
- {__move_assign_alloc(__c, integral_constant<bool,
- __alloc_traits::propagate_on_container_move_assignment::value>());}
-private:
- _LIBCPP_INLINE_VISIBILITY
- void __copy_assign_alloc(const __vector_base& __c, true_type)
- {
- if (__alloc() != __c.__alloc())
- {
- clear();
- __alloc_traits::deallocate(__alloc(), __begin_, capacity());
- __begin_ = __end_ = __end_cap() = nullptr;
- }
- __alloc() = __c.__alloc();
- }
-
- _LIBCPP_INLINE_VISIBILITY
- void __copy_assign_alloc(const __vector_base&, false_type)
- {}
-
- _LIBCPP_INLINE_VISIBILITY
- void __move_assign_alloc(__vector_base& __c, true_type)
- _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
- {
- __alloc() = _VSTD::move(__c.__alloc());
- }
-
- _LIBCPP_INLINE_VISIBILITY
- void __move_assign_alloc(__vector_base&, false_type)
- _NOEXCEPT
- {}
-};
-
-template <class _Tp, class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
-void
-__vector_base<_Tp, _Allocator>::__destruct_at_end(pointer __new_last) _NOEXCEPT
-{
- pointer __soon_to_be_end = __end_;
- while (__new_last != __soon_to_be_end)
- __alloc_traits::destroy(__alloc(), _VSTD::__to_address(--__soon_to_be_end));
- __end_ = __new_last;
-}
-
-template <class _Tp, class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
-__vector_base<_Tp, _Allocator>::__vector_base()
_NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
- : __begin_(nullptr),
- __end_(nullptr),
- __end_cap_(nullptr, __default_init_tag())
-{
-}
+ : __begin_(nullptr),
+ __end_(nullptr),
+ __end_cap_(nullptr, __default_init_tag()) {}
-template <class _Tp, class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
-__vector_base<_Tp, _Allocator>::__vector_base(const allocator_type& __a)
- : __begin_(nullptr),
- __end_(nullptr),
- __end_cap_(nullptr, __a)
-{
-}
+ _LIBCPP_INLINE_VISIBILITY __vector_base(const allocator_type& __a)
+ : __begin_(nullptr),
+ __end_(nullptr),
+ __end_cap_(nullptr, __a) {}
#ifndef _LIBCPP_CXX03_LANG
-template <class _Tp, class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
-__vector_base<_Tp, _Allocator>::__vector_base(allocator_type&& __a) _NOEXCEPT
- : __begin_(nullptr),
- __end_(nullptr),
- __end_cap_(nullptr, _VSTD::move(__a)) {}
+ _LIBCPP_INLINE_VISIBILITY __vector_base(allocator_type&& __a) _NOEXCEPT
+ : __begin_(nullptr),
+ __end_(nullptr),
+ __end_cap_(nullptr, _VSTD::move(__a)) {}
#endif
-
-template <class _Tp, class _Allocator>
-__vector_base<_Tp, _Allocator>::~__vector_base()
-{
- if (__begin_ != nullptr)
- {
- clear();
- __alloc_traits::deallocate(__alloc(), __begin_, capacity());
- }
-}
+};
template <class _Tp, class _Allocator /* = allocator<_Tp> */>
class _LIBCPP_TEMPLATE_VIS vector
+ // This base class is historical, but it needs to remain for ABI compatibility.
: private __vector_base<_Tp, _Allocator>
{
private:
- typedef __vector_base<_Tp, _Allocator> __base;
- typedef allocator<_Tp> __default_allocator_type;
+ typedef __vector_base<_Tp, _Allocator> __base;
+ typedef allocator<_Tp> __default_allocator_type;
public:
- typedef vector __self;
- typedef _Tp value_type;
- typedef _Allocator allocator_type;
- typedef typename __base::__alloc_traits __alloc_traits;
- typedef typename __base::reference reference;
- typedef typename __base::const_reference const_reference;
- typedef typename __base::size_type size_type;
- typedef typename __base::difference_type difference_type;
- typedef typename __base::pointer pointer;
- typedef typename __base::const_pointer const_pointer;
- typedef __wrap_iter<pointer> iterator;
- typedef __wrap_iter<const_pointer> const_iterator;
- typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
- typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
+ typedef vector __self;
+ typedef _Tp value_type;
+ typedef _Allocator allocator_type;
+ typedef allocator_traits<allocator_type> __alloc_traits;
+ typedef value_type& reference;
+ typedef const value_type& const_reference;
+ typedef typename __allocator_traits<allocator_type>::size_type size_type;
+ typedef typename __alloc_traits::difference_type difference_type;
+ typedef typename __alloc_traits::pointer pointer;
+ typedef typename __alloc_traits::const_pointer const_pointer;
+ typedef __wrap_iter<pointer> iterator;
+ typedef __wrap_iter<const_pointer> const_iterator;
+ typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
+ typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
static_assert((is_same<typename allocator_type::value_type, value_type>::value),
"Allocator::value_type must be same type as value_type");
@@ -552,10 +428,16 @@ public:
_LIBCPP_INLINE_VISIBILITY
~vector()
{
- __annotate_delete();
+ __annotate_delete();
#if _LIBCPP_DEBUG_LEVEL == 2
- __get_db()->__erase_c(this);
+ __get_db()->__erase_c(this);
#endif
+
+ if (this->__begin_ != nullptr)
+ {
+ __clear();
+ __alloc_traits::deallocate(__alloc(), this->__begin_, capacity());
+ }
}
vector(const vector& __x);
@@ -660,7 +542,7 @@ public:
{return static_cast<size_type>(this->__end_ - this->__begin_);}
_LIBCPP_INLINE_VISIBILITY
size_type capacity() const _NOEXCEPT
- {return __base::capacity();}
+ {return static_cast<size_type>(__end_cap() - this->__begin_);}
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
bool empty() const _NOEXCEPT
{return this->__begin_ == this->__end_;}
@@ -773,7 +655,7 @@ public:
void clear() _NOEXCEPT
{
size_type __old_size = size();
- __base::clear();
+ __clear();
__annotate_shrink(__old_size);
__invalidate_all_iterators();
}
@@ -834,7 +716,7 @@ private:
{
__invalidate_iterators_past(__new_last);
size_type __old_size = size();
- __base::__destruct_at_end(__new_last);
+ __base_destruct_at_end(__new_last);
__annotate_shrink(__old_size);
}
@@ -898,7 +780,7 @@ private:
struct _ConstructTransaction {
explicit _ConstructTransaction(vector &__v, size_type __n)
- : __v_(__v), __pos_(__v.__end_), __new_end_(__v.__end_ + __n) {
+ : __v_(__v), __pos_(__v.__end_), __new_end_(__v.__end_ + __n) {
#ifndef _LIBCPP_HAS_NO_ASAN
__v_.__annotate_increase(__n);
#endif
@@ -929,19 +811,104 @@ private:
_VSTD::forward<_Args>(__args)...);
++__tx.__pos_;
}
+
+ _LIBCPP_INLINE_VISIBILITY
+ allocator_type& __alloc() _NOEXCEPT
+ {return this->__end_cap_.second();}
+ _LIBCPP_INLINE_VISIBILITY
+ const allocator_type& __alloc() const _NOEXCEPT
+ {return this->__end_cap_.second();}
+ _LIBCPP_INLINE_VISIBILITY
+ pointer& __end_cap() _NOEXCEPT
+ {return this->__end_cap_.first();}
+ _LIBCPP_INLINE_VISIBILITY
+ const pointer& __end_cap() const _NOEXCEPT
+ {return this->__end_cap_.first();}
+
+ _LIBCPP_INLINE_VISIBILITY
+ void __clear() _NOEXCEPT {__base_destruct_at_end(this->__begin_);}
+
+ _LIBCPP_INLINE_VISIBILITY
+ void __base_destruct_at_end(pointer __new_last) _NOEXCEPT {
+ pointer __soon_to_be_end = this->__end_;
+ while (__new_last != __soon_to_be_end)
+ __alloc_traits::destroy(__alloc(), _VSTD::__to_address(--__soon_to_be_end));
+ this->__end_ = __new_last;
+ }
+
+ _LIBCPP_INLINE_VISIBILITY
+ void __copy_assign_alloc(const vector& __c)
+ {__copy_assign_alloc(__c, integral_constant<bool,
+ __alloc_traits::propagate_on_container_copy_assignment::value>());}
+
+ _LIBCPP_INLINE_VISIBILITY
+ void __move_assign_alloc(vector& __c)
+ _NOEXCEPT_(
+ !__alloc_traits::propagate_on_container_move_assignment::value ||
+ is_nothrow_move_assignable<allocator_type>::value)
+ {__move_assign_alloc(__c, integral_constant<bool,
+ __alloc_traits::propagate_on_container_move_assignment::value>());}
+
+ _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
+ void __throw_length_error() const {
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ __vector_base_common<true>::__throw_length_error();
+#else
+ _VSTD::abort();
+#endif
+ }
+
+ _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
+ void __throw_out_of_range() const {
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ __vector_base_common<true>::__throw_out_of_range();
+#else
+ _VSTD::abort();
+#endif
+ }
+
+ _LIBCPP_INLINE_VISIBILITY
+ void __copy_assign_alloc(const vector& __c, true_type)
+ {
+ if (__alloc() != __c.__alloc())
+ {
+ __clear();
+ __alloc_traits::deallocate(__alloc(), this->__begin_, capacity());
+ this->__begin_ = this->__end_ = __end_cap() = nullptr;
+ }
+ __alloc() = __c.__alloc();
+ }
+
+ _LIBCPP_INLINE_VISIBILITY
+ void __copy_assign_alloc(const vector&, false_type)
+ {}
+
+ _LIBCPP_INLINE_VISIBILITY
+ void __move_assign_alloc(vector& __c, true_type)
+ _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
+ {
+ __alloc() = _VSTD::move(__c.__alloc());
+ }
+
+ _LIBCPP_INLINE_VISIBILITY
+ void __move_assign_alloc(vector&, false_type)
+ _NOEXCEPT
+ {}
};
-#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
+#if _LIBCPP_STD_VER >= 17
template<class _InputIterator,
class _Alloc = allocator<__iter_value_type<_InputIterator>>,
- class = _EnableIf<__is_allocator<_Alloc>::value>
+ class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
+ class = enable_if_t<__is_allocator<_Alloc>::value>
>
vector(_InputIterator, _InputIterator)
-> vector<__iter_value_type<_InputIterator>, _Alloc>;
template<class _InputIterator,
class _Alloc,
- class = _EnableIf<__is_allocator<_Alloc>::value>
+ class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
+ class = enable_if_t<__is_allocator<_Alloc>::value>
>
vector(_InputIterator, _InputIterator, _Alloc)
-> vector<__iter_value_type<_InputIterator>, _Alloc>;
@@ -1043,7 +1010,7 @@ vector<_Tp, _Allocator>::__construct_at_end(size_type __n)
{
_ConstructTransaction __tx(*this, __n);
const_pointer __new_end = __tx.__new_end_;
- for (pointer __pos = __tx.__pos_; __pos != __new_end; ++__pos, __tx.__pos_ = __pos) {
+ for (pointer __pos = __tx.__pos_; __pos != __new_end; __tx.__pos_ = ++__pos) {
__alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__pos));
}
}
@@ -1061,7 +1028,7 @@ vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x)
{
_ConstructTransaction __tx(*this, __n);
const_pointer __new_end = __tx.__new_end_;
- for (pointer __pos = __tx.__pos_; __pos != __new_end; ++__pos, __tx.__pos_ = __pos) {
+ for (pointer __pos = __tx.__pos_; __pos != __new_end; __tx.__pos_ = ++__pos) {
__alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__pos), __x);
}
}
@@ -1291,7 +1258,7 @@ vector<_Tp, _Allocator>::vector(vector&& __x)
{
#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->__insert_c(this);
- __get_db()->swap(this, &__x);
+ __get_db()->swap(this, _VSTD::addressof(__x));
#endif
this->__begin_ = __x.__begin_;
this->__end_ = __x.__end_;
@@ -1314,7 +1281,7 @@ vector<_Tp, _Allocator>::vector(vector&& __x, const __identity_t<allocator_type>
this->__end_cap() = __x.__end_cap();
__x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
#if _LIBCPP_DEBUG_LEVEL == 2
- __get_db()->swap(this, &__x);
+ __get_db()->swap(this, _VSTD::addressof(__x));
#endif
}
else
@@ -1369,7 +1336,7 @@ void
vector<_Tp, _Allocator>::__move_assign(vector& __c, false_type)
_NOEXCEPT_(__alloc_traits::is_always_equal::value)
{
- if (__base::__alloc() != __c.__alloc())
+ if (__alloc() != __c.__alloc())
{
typedef move_iterator<iterator> _Ip;
assign(_Ip(__c.begin()), _Ip(__c.end()));
@@ -1384,13 +1351,13 @@ vector<_Tp, _Allocator>::__move_assign(vector& __c, true_type)
_NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
{
__vdeallocate();
- __base::__move_assign_alloc(__c); // this can throw
+ __move_assign_alloc(__c); // this can throw
this->__begin_ = __c.__begin_;
this->__end_ = __c.__end_;
this->__end_cap() = __c.__end_cap();
__c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr;
#if _LIBCPP_DEBUG_LEVEL == 2
- __get_db()->swap(this, &__c);
+ __get_db()->swap(this, _VSTD::addressof(__c));
#endif
}
@@ -1401,9 +1368,9 @@ inline _LIBCPP_INLINE_VISIBILITY
vector<_Tp, _Allocator>&
vector<_Tp, _Allocator>::operator=(const vector& __x)
{
- if (this != &__x)
+ if (this != _VSTD::addressof(__x))
{
- __base::__copy_assign_alloc(__x);
+ __copy_assign_alloc(__x);
assign(__x.__begin_, __x.__end_);
}
return *this;
@@ -1585,6 +1552,8 @@ vector<_Tp, _Allocator>::reserve(size_type __n)
{
if (__n > capacity())
{
+ if (__n > max_size())
+ this->__throw_length_error();
allocator_type& __a = this->__alloc();
__split_buffer<value_type, allocator_type&> __v(__n, size(), __a);
__swap_out_circular_buffer(__v);
@@ -1709,7 +1678,7 @@ typename vector<_Tp, _Allocator>::iterator
vector<_Tp, _Allocator>::erase(const_iterator __position)
{
#if _LIBCPP_DEBUG_LEVEL == 2
- _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
+ _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this,
"vector::erase(iterator) called with an iterator not"
" referring to this vector");
#endif
@@ -1728,11 +1697,11 @@ typename vector<_Tp, _Allocator>::iterator
vector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last)
{
#if _LIBCPP_DEBUG_LEVEL == 2
- _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
- "vector::erase(iterator, iterator) called with an iterator not"
+ _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__first)) == this,
+ "vector::erase(iterator, iterator) called with an iterator not"
" referring to this vector");
- _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__last) == this,
- "vector::erase(iterator, iterator) called with an iterator not"
+ _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__last)) == this,
+ "vector::erase(iterator, iterator) called with an iterator not"
" referring to this vector");
#endif
_LIBCPP_ASSERT(__first <= __last, "vector::erase(first, last) called with invalid range");
@@ -1755,7 +1724,7 @@ vector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointe
pointer __i = __from_s + __n;
_ConstructTransaction __tx(*this, __from_e - __i);
for (pointer __pos = __tx.__pos_; __i < __from_e;
- ++__i, ++__pos, __tx.__pos_ = __pos) {
+ ++__i, (void) ++__pos, __tx.__pos_ = __pos) {
__alloc_traits::construct(this->__alloc(),
_VSTD::__to_address(__pos),
_VSTD::move(*__i));
@@ -1769,7 +1738,7 @@ typename vector<_Tp, _Allocator>::iterator
vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x)
{
#if _LIBCPP_DEBUG_LEVEL == 2
- _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
+ _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this,
"vector::insert(iterator, x) called with an iterator not"
" referring to this vector");
#endif
@@ -1806,7 +1775,7 @@ typename vector<_Tp, _Allocator>::iterator
vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x)
{
#if _LIBCPP_DEBUG_LEVEL == 2
- _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
+ _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this,
"vector::insert(iterator, x) called with an iterator not"
" referring to this vector");
#endif
@@ -1839,7 +1808,7 @@ typename vector<_Tp, _Allocator>::iterator
vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args)
{
#if _LIBCPP_DEBUG_LEVEL == 2
- _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
+ _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this,
"vector::emplace(iterator, x) called with an iterator not"
" referring to this vector");
#endif
@@ -1874,7 +1843,7 @@ typename vector<_Tp, _Allocator>::iterator
vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x)
{
#if _LIBCPP_DEBUG_LEVEL == 2
- _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
+ _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this,
"vector::insert(iterator, n, x) called with an iterator not"
" referring to this vector");
#endif
@@ -1925,7 +1894,7 @@ typename enable_if
vector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
{
#if _LIBCPP_DEBUG_LEVEL == 2
- _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
+ _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this,
"vector::insert(iterator, range) called with an iterator not"
" referring to this vector");
#endif
@@ -1978,7 +1947,7 @@ typename enable_if
vector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
{
#if _LIBCPP_DEBUG_LEVEL == 2
- _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
+ _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this,
"vector::insert(iterator, range) called with an iterator not"
" referring to this vector");
#endif
@@ -2059,7 +2028,7 @@ vector<_Tp, _Allocator>::swap(vector& __x)
_VSTD::__swap_allocator(this->__alloc(), __x.__alloc(),
integral_constant<bool,__alloc_traits::propagate_on_container_swap::value>());
#if _LIBCPP_DEBUG_LEVEL == 2
- __get_db()->swap(this, &__x);
+ __get_db()->swap(this, _VSTD::addressof(__x));
#endif
}
@@ -2854,7 +2823,7 @@ template <class _Allocator>
vector<bool, _Allocator>&
vector<bool, _Allocator>::operator=(const vector& __v)
{
- if (this != &__v)
+ if (this != _VSTD::addressof(__v))
{
__copy_assign_alloc(__v);
if (__v.__size_)
@@ -2958,7 +2927,7 @@ vector<bool, _Allocator>::assign(size_type __n, const value_type& __x)
__size_ = __n;
else
{
- vector __v(__alloc());
+ vector __v(get_allocator());
__v.reserve(__recommend(__n));
__v.__size_ = __n;
swap(__v);
@@ -3013,7 +2982,9 @@ vector<bool, _Allocator>::reserve(size_type __n)
{
if (__n > capacity())
{
- vector __v(this->__alloc());
+ if (__n > max_size())
+ this->__throw_length_error();
+ vector __v(this->get_allocator());
__v.__vallocate(__n);
__v.__construct_at_end(this->begin(), this->end());
swap(__v);
@@ -3083,7 +3054,7 @@ vector<bool, _Allocator>::insert(const_iterator __position, const value_type& __
}
else
{
- vector __v(__alloc());
+ vector __v(get_allocator());
__v.reserve(__recommend(__size_ + 1));
__v.__size_ = __size_ + 1;
__r = _VSTD::copy(cbegin(), __position, __v.begin());
@@ -3109,7 +3080,7 @@ vector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const
}
else
{
- vector __v(__alloc());
+ vector __v(get_allocator());
__v.reserve(__recommend(__size_ + __n));
__v.__size_ = __size_ + __n;
__r = _VSTD::copy(cbegin(), __position, __v.begin());
@@ -3138,7 +3109,7 @@ vector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __fir
++this->__size_;
back() = *__first;
}
- vector __v(__alloc());
+ vector __v(get_allocator());
if (__first != __last)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
@@ -3188,7 +3159,7 @@ vector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __f
}
else
{
- vector __v(__alloc());
+ vector __v(get_allocator());
__v.reserve(__recommend(__size_ + __n));
__v.__size_ = __size_ + __n;
__r = _VSTD::copy(cbegin(), __position, __v.begin());
@@ -3255,7 +3226,7 @@ vector<bool, _Allocator>::resize(size_type __sz, value_type __x)
}
else
{
- vector __v(__alloc());
+ vector __v(get_allocator());
__v.reserve(__recommend(__size_ + __n));
__v.__size_ = __size_ + __n;
__r = _VSTD::copy(cbegin(), cend(), __v.begin());