aboutsummaryrefslogtreecommitdiff
path: root/libcxx/include/vector
diff options
context:
space:
mode:
Diffstat (limited to 'libcxx/include/vector')
-rw-r--r--libcxx/include/vector452
1 files changed, 181 insertions, 271 deletions
diff --git a/libcxx/include/vector b/libcxx/include/vector
index fd0fb0db2756..f5c09011948d 100644
--- a/libcxx/include/vector
+++ b/libcxx/include/vector
@@ -271,20 +271,33 @@ erase_if(vector<T, Allocator>& c, Predicate pred); // C++20
*/
+#include <__algorithm/copy.h>
+#include <__algorithm/equal.h>
+#include <__algorithm/fill_n.h>
+#include <__algorithm/lexicographical_compare.h>
+#include <__algorithm/remove.h>
+#include <__algorithm/remove_if.h>
+#include <__algorithm/rotate.h>
+#include <__algorithm/unwrap_iter.h>
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__bit_reference>
#include <__config>
#include <__debug>
-#include <__functional_base>
+#include <__format/enable_insertable.h>
+#include <__functional/hash.h>
+#include <__functional/unary_function.h>
+#include <__iterator/advance.h>
#include <__iterator/iterator_traits.h>
+#include <__iterator/reverse_iterator.h>
#include <__iterator/wrap_iter.h>
+#include <__memory/allocate_at_least.h>
#include <__split_buffer>
#include <__utility/forward.h>
-#include <algorithm>
+#include <__utility/move.h>
+#include <__utility/swap.h>
#include <climits>
-#include <compare>
#include <cstdlib>
#include <cstring>
-#include <initializer_list>
#include <iosfwd> // for forward declaration of vector
#include <limits>
#include <memory>
@@ -292,65 +305,39 @@ erase_if(vector<T, Allocator>& c, Predicate pred); // C++20
#include <type_traits>
#include <version>
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#pragma GCC system_header
+#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
+# include <algorithm>
+# include <typeinfo>
+# include <utility>
#endif
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
+// standard-mandated includes
-_LIBCPP_BEGIN_NAMESPACE_STD
-
-template <bool>
-struct __vector_base_common;
-
-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;
-};
+// [iterator.range]
+#include <__iterator/access.h>
+#include <__iterator/data.h>
+#include <__iterator/empty.h>
+#include <__iterator/reverse_access.h>
+#include <__iterator/size.h>
-template <class _Tp, class _Allocator>
-class __vector_base
- : protected __vector_base_common<true> // This base class is historical, but it needs to remain for ABI compatibility
-{
- typedef _Allocator allocator_type;
- typedef typename allocator_traits<allocator_type>::pointer pointer;
+// [vector.syn]
+#include <compare>
+#include <initializer_list>
-protected:
- pointer __begin_;
- pointer __end_;
- __compressed_pair<pointer, allocator_type> __end_cap_;
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
- _LIBCPP_INLINE_VISIBILITY
- __vector_base()
- _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
- : __begin_(nullptr),
- __end_(nullptr),
- __end_cap_(nullptr, __default_init_tag()) {}
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
- _LIBCPP_INLINE_VISIBILITY __vector_base(const allocator_type& __a)
- : __begin_(nullptr),
- __end_(nullptr),
- __end_cap_(nullptr, __a) {}
-#ifndef _LIBCPP_CXX03_LANG
- _LIBCPP_INLINE_VISIBILITY __vector_base(allocator_type&& __a) _NOEXCEPT
- : __begin_(nullptr),
- __end_(nullptr),
- __end_cap_(nullptr, _VSTD::move(__a)) {}
-#endif
-};
+_LIBCPP_BEGIN_NAMESPACE_STD
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;
public:
typedef vector __self;
@@ -382,7 +369,7 @@ public:
#else
_NOEXCEPT
#endif
- : __base(__a)
+ : __end_cap_(nullptr, __a)
{
_VSTD::__debug_db_insert_c(this);
}
@@ -394,7 +381,7 @@ public:
template <class = __enable_if_t<__is_allocator<_Allocator>::value> >
vector(size_type __n, const value_type& __x, const allocator_type& __a)
- : __base(__a)
+ : __end_cap_(nullptr, __a)
{
_VSTD::__debug_db_insert_c(this);
if (__n > 0)
@@ -437,9 +424,7 @@ public:
~vector()
{
__annotate_delete();
-#if _LIBCPP_DEBUG_LEVEL == 2
- __get_db()->__erase_c(this);
-#endif
+ std::__debug_db_erase_c(this);
if (this->__begin_ != nullptr)
{
@@ -449,7 +434,7 @@ public:
}
vector(const vector& __x);
- vector(const vector& __x, const __identity_t<allocator_type>& __a);
+ vector(const vector& __x, const __type_identity_t<allocator_type>& __a);
_LIBCPP_INLINE_VISIBILITY
vector& operator=(const vector& __x);
@@ -461,25 +446,24 @@ public:
vector(initializer_list<value_type> __il, const allocator_type& __a);
_LIBCPP_INLINE_VISIBILITY
+ vector& operator=(initializer_list<value_type> __il)
+ {assign(__il.begin(), __il.end()); return *this;}
+#endif // !_LIBCPP_CXX03_LANG
+
+ _LIBCPP_INLINE_VISIBILITY
vector(vector&& __x)
#if _LIBCPP_STD_VER > 14
- _NOEXCEPT;
+ noexcept;
#else
_NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
#endif
_LIBCPP_INLINE_VISIBILITY
- vector(vector&& __x, const __identity_t<allocator_type>& __a);
+ vector(vector&& __x, const __type_identity_t<allocator_type>& __a);
_LIBCPP_INLINE_VISIBILITY
vector& operator=(vector&& __x)
_NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
- _LIBCPP_INLINE_VISIBILITY
- vector& operator=(initializer_list<value_type> __il)
- {assign(__il.begin(), __il.end()); return *this;}
-
-#endif // !_LIBCPP_CXX03_LANG
-
template <class _InputIterator>
typename enable_if
<
@@ -591,41 +575,26 @@ public:
const value_type* data() const _NOEXCEPT
{return _VSTD::__to_address(this->__begin_);}
-#ifdef _LIBCPP_CXX03_LANG
- _LIBCPP_INLINE_VISIBILITY
- void __emplace_back(const value_type& __x) { push_back(__x); }
-#else
- template <class _Arg>
- _LIBCPP_INLINE_VISIBILITY
- void __emplace_back(_Arg&& __arg) {
- emplace_back(_VSTD::forward<_Arg>(__arg));
- }
-#endif
-
_LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x);
-#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY void push_back(value_type&& __x);
template <class... _Args>
- _LIBCPP_INLINE_VISIBILITY
+ _LIBCPP_INLINE_VISIBILITY
#if _LIBCPP_STD_VER > 14
reference emplace_back(_Args&&... __args);
#else
void emplace_back(_Args&&... __args);
#endif
-#endif // !_LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
void pop_back();
iterator insert(const_iterator __position, const_reference __x);
-#ifndef _LIBCPP_CXX03_LANG
iterator insert(const_iterator __position, value_type&& __x);
template <class... _Args>
- iterator emplace(const_iterator __position, _Args&&... __args);
-#endif // !_LIBCPP_CXX03_LANG
+ iterator emplace(const_iterator __position, _Args&&... __args);
iterator insert(const_iterator __position, size_type __n, const_reference __x);
template <class _InputIterator>
@@ -665,7 +634,7 @@ public:
size_type __old_size = size();
__clear();
__annotate_shrink(__old_size);
- __invalidate_all_iterators();
+ std::__debug_db_invalidate_all(this);
}
void resize(size_type __sz);
@@ -681,19 +650,41 @@ public:
bool __invariants() const;
-#if _LIBCPP_DEBUG_LEVEL == 2
+#ifdef _LIBCPP_ENABLE_DEBUG_MODE
bool __dereferenceable(const const_iterator* __i) const;
bool __decrementable(const const_iterator* __i) const;
bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
-#endif // _LIBCPP_DEBUG_LEVEL == 2
+#endif // _LIBCPP_ENABLE_DEBUG_MODE
private:
- _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
+ pointer __begin_ = nullptr;
+ pointer __end_ = nullptr;
+ __compressed_pair<pointer, allocator_type> __end_cap_ =
+ __compressed_pair<pointer, allocator_type>(nullptr, __default_init_tag());
+
_LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(pointer __new_last);
- void __vallocate(size_type __n);
+
+
+ // Allocate space for __n objects
+ // throws length_error if __n > max_size()
+ // throws (probably bad_alloc) if memory run out
+ // Precondition: __begin_ == __end_ == __end_cap() == 0
+ // Precondition: __n > 0
+ // Postcondition: capacity() >= __n
+ // Postcondition: size() == 0
+ _LIBCPP_HIDE_FROM_ABI void __vallocate(size_type __n) {
+ if (__n > max_size())
+ __throw_length_error();
+ auto __allocation = std::__allocate_at_least(__alloc(), __n);
+ __begin_ = __allocation.ptr;
+ __end_ = __allocation.ptr;
+ __end_cap() = __begin_ + __allocation.count;
+ __annotate_new(0);
+ }
+
void __vdeallocate() _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
void __construct_at_end(size_type __n);
@@ -728,7 +719,6 @@ private:
__annotate_shrink(__old_size);
}
-#ifndef _LIBCPP_CXX03_LANG
template <class _Up>
_LIBCPP_INLINE_VISIBILITY
inline void __push_back_slow_path(_Up&& __x);
@@ -736,11 +726,6 @@ private:
template <class... _Args>
_LIBCPP_INLINE_VISIBILITY
inline void __emplace_back_slow_path(_Args&&... __args);
-#else
- template <class _Up>
- _LIBCPP_INLINE_VISIBILITY
- inline void __push_back_slow_path(_Up& __x);
-#endif
// The following functions are no-ops outside of AddressSanitizer mode.
// We call annotatations only for the default Allocator because other allocators
@@ -859,20 +844,12 @@ private:
_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
+ _VSTD::__throw_length_error("vector");
}
_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
+ _VSTD::__throw_out_of_range("vector");
}
_LIBCPP_INLINE_VISIBILITY
@@ -934,7 +911,7 @@ vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, a
_VSTD::swap(this->__end_cap(), __v.__end_cap());
__v.__first_ = __v.__begin_;
__annotate_new(size());
- __invalidate_all_iterators();
+ std::__debug_db_invalidate_all(this);
}
template <class _Tp, class _Allocator>
@@ -950,28 +927,10 @@ vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, a
_VSTD::swap(this->__end_cap(), __v.__end_cap());
__v.__first_ = __v.__begin_;
__annotate_new(size());
- __invalidate_all_iterators();
+ std::__debug_db_invalidate_all(this);
return __r;
}
-// Allocate space for __n objects
-// throws length_error if __n > max_size()
-// throws (probably bad_alloc) if memory run out
-// Precondition: __begin_ == __end_ == __end_cap() == 0
-// Precondition: __n > 0
-// Postcondition: capacity() == __n
-// Postcondition: size() == 0
-template <class _Tp, class _Allocator>
-void
-vector<_Tp, _Allocator>::__vallocate(size_type __n)
-{
- if (__n > max_size())
- this->__throw_length_error();
- this->__begin_ = this->__end_ = __alloc_traits::allocate(this->__alloc(), __n);
- this->__end_cap() = this->__begin_ + __n;
- __annotate_new(0);
-}
-
template <class _Tp, class _Allocator>
void
vector<_Tp, _Allocator>::__vdeallocate() _NOEXCEPT
@@ -1106,7 +1065,7 @@ vector<_Tp, _Allocator>::vector(size_type __n)
#if _LIBCPP_STD_VER > 11
template <class _Tp, class _Allocator>
vector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a)
- : __base(__a)
+ : __end_cap_(nullptr, __a)
{
_VSTD::__debug_db_insert_c(this);
if (__n > 0)
@@ -1140,7 +1099,7 @@ vector<_Tp, _Allocator>::vector(_InputIterator __first,
{
_VSTD::__debug_db_insert_c(this);
for (; __first != __last; ++__first)
- __emplace_back(*__first);
+ emplace_back(*__first);
}
template <class _Tp, class _Allocator>
@@ -1151,11 +1110,11 @@ vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, c
is_constructible<
value_type,
typename iterator_traits<_InputIterator>::reference>::value>::type*)
- : __base(__a)
+ : __end_cap_(nullptr, __a)
{
_VSTD::__debug_db_insert_c(this);
for (; __first != __last; ++__first)
- __emplace_back(*__first);
+ emplace_back(*__first);
}
template <class _Tp, class _Allocator>
@@ -1183,7 +1142,7 @@ vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __las
is_constructible<
value_type,
typename iterator_traits<_ForwardIterator>::reference>::value>::type*)
- : __base(__a)
+ : __end_cap_(nullptr, __a)
{
_VSTD::__debug_db_insert_c(this);
size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
@@ -1196,7 +1155,7 @@ vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __las
template <class _Tp, class _Allocator>
vector<_Tp, _Allocator>::vector(const vector& __x)
- : __base(__alloc_traits::select_on_container_copy_construction(__x.__alloc()))
+ : __end_cap_(nullptr, __alloc_traits::select_on_container_copy_construction(__x.__alloc()))
{
_VSTD::__debug_db_insert_c(this);
size_type __n = __x.size();
@@ -1208,8 +1167,8 @@ vector<_Tp, _Allocator>::vector(const vector& __x)
}
template <class _Tp, class _Allocator>
-vector<_Tp, _Allocator>::vector(const vector& __x, const __identity_t<allocator_type>& __a)
- : __base(__a)
+vector<_Tp, _Allocator>::vector(const vector& __x, const __type_identity_t<allocator_type>& __a)
+ : __end_cap_(nullptr, __a)
{
_VSTD::__debug_db_insert_c(this);
size_type __n = __x.size();
@@ -1220,22 +1179,18 @@ vector<_Tp, _Allocator>::vector(const vector& __x, const __identity_t<allocator_
}
}
-#ifndef _LIBCPP_CXX03_LANG
-
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
vector<_Tp, _Allocator>::vector(vector&& __x)
#if _LIBCPP_STD_VER > 14
- _NOEXCEPT
+ noexcept
#else
_NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
#endif
- : __base(_VSTD::move(__x.__alloc()))
+ : __end_cap_(nullptr, _VSTD::move(__x.__alloc()))
{
_VSTD::__debug_db_insert_c(this);
-#if _LIBCPP_DEBUG_LEVEL == 2
- __get_db()->swap(this, _VSTD::addressof(__x));
-#endif
+ std::__debug_db_swap(this, std::addressof(__x));
this->__begin_ = __x.__begin_;
this->__end_ = __x.__end_;
this->__end_cap() = __x.__end_cap();
@@ -1244,8 +1199,8 @@ vector<_Tp, _Allocator>::vector(vector&& __x)
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
-vector<_Tp, _Allocator>::vector(vector&& __x, const __identity_t<allocator_type>& __a)
- : __base(__a)
+vector<_Tp, _Allocator>::vector(vector&& __x, const __type_identity_t<allocator_type>& __a)
+ : __end_cap_(nullptr, __a)
{
_VSTD::__debug_db_insert_c(this);
if (__a == __x.__alloc())
@@ -1254,9 +1209,7 @@ vector<_Tp, _Allocator>::vector(vector&& __x, const __identity_t<allocator_type>
this->__end_ = __x.__end_;
this->__end_cap() = __x.__end_cap();
__x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
-#if _LIBCPP_DEBUG_LEVEL == 2
- __get_db()->swap(this, _VSTD::addressof(__x));
-#endif
+ std::__debug_db_swap(this, std::addressof(__x));
}
else
{
@@ -1265,6 +1218,8 @@ vector<_Tp, _Allocator>::vector(vector&& __x, const __identity_t<allocator_type>
}
}
+#ifndef _LIBCPP_CXX03_LANG
+
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il)
@@ -1280,7 +1235,7 @@ vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il)
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
- : __base(__a)
+ : __end_cap_(nullptr, __a)
{
_VSTD::__debug_db_insert_c(this);
if (__il.size() > 0)
@@ -1290,6 +1245,8 @@ vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocat
}
}
+#endif // _LIBCPP_CXX03_LANG
+
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
vector<_Tp, _Allocator>&
@@ -1326,13 +1283,9 @@ vector<_Tp, _Allocator>::__move_assign(vector& __c, true_type)
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, _VSTD::addressof(__c));
-#endif
+ std::__debug_db_swap(this, std::addressof(__c));
}
-#endif // !_LIBCPP_CXX03_LANG
-
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
vector<_Tp, _Allocator>&
@@ -1361,7 +1314,7 @@ vector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
{
clear();
for (; __first != __last; ++__first)
- __emplace_back(*__first);
+ emplace_back(*__first);
}
template <class _Tp, class _Allocator>
@@ -1399,7 +1352,7 @@ vector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __las
__vallocate(__recommend(__new_size));
__construct_at_end(__first, __last, __new_size);
}
- __invalidate_all_iterators();
+ std::__debug_db_invalidate_all(this);
}
template <class _Tp, class _Allocator>
@@ -1421,31 +1374,7 @@ vector<_Tp, _Allocator>::assign(size_type __n, const_reference __u)
__vallocate(__recommend(static_cast<size_type>(__n)));
__construct_at_end(__n, __u);
}
- __invalidate_all_iterators();
-}
-
-template <class _Tp, class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
-typename vector<_Tp, _Allocator>::iterator
-vector<_Tp, _Allocator>::__make_iter(pointer __p) _NOEXCEPT
-{
-#if _LIBCPP_DEBUG_LEVEL == 2
- return iterator(this, __p);
-#else
- return iterator(__p);
-#endif
-}
-
-template <class _Tp, class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
-typename vector<_Tp, _Allocator>::const_iterator
-vector<_Tp, _Allocator>::__make_iter(const_pointer __p) const _NOEXCEPT
-{
-#if _LIBCPP_DEBUG_LEVEL == 2
- return const_iterator(this, __p);
-#else
- return const_iterator(__p);
-#endif
+ std::__debug_db_invalidate_all(this);
}
template <class _Tp, class _Allocator>
@@ -1453,7 +1382,7 @@ inline _LIBCPP_INLINE_VISIBILITY
typename vector<_Tp, _Allocator>::iterator
vector<_Tp, _Allocator>::begin() _NOEXCEPT
{
- return __make_iter(this->__begin_);
+ return iterator(this, this->__begin_);
}
template <class _Tp, class _Allocator>
@@ -1461,7 +1390,7 @@ inline _LIBCPP_INLINE_VISIBILITY
typename vector<_Tp, _Allocator>::const_iterator
vector<_Tp, _Allocator>::begin() const _NOEXCEPT
{
- return __make_iter(this->__begin_);
+ return const_iterator(this, this->__begin_);
}
template <class _Tp, class _Allocator>
@@ -1469,7 +1398,7 @@ inline _LIBCPP_INLINE_VISIBILITY
typename vector<_Tp, _Allocator>::iterator
vector<_Tp, _Allocator>::end() _NOEXCEPT
{
- return __make_iter(this->__end_);
+ return iterator(this, this->__end_);
}
template <class _Tp, class _Allocator>
@@ -1477,7 +1406,7 @@ inline _LIBCPP_INLINE_VISIBILITY
typename vector<_Tp, _Allocator>::const_iterator
vector<_Tp, _Allocator>::end() const _NOEXCEPT
{
- return __make_iter(this->__end_);
+ return const_iterator(this, this->__end_);
}
template <class _Tp, class _Allocator>
@@ -1555,11 +1484,7 @@ vector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT
template <class _Tp, class _Allocator>
template <class _Up>
void
-#ifndef _LIBCPP_CXX03_LANG
vector<_Tp, _Allocator>::__push_back_slow_path(_Up&& __x)
-#else
-vector<_Tp, _Allocator>::__push_back_slow_path(_Up& __x)
-#endif
{
allocator_type& __a = this->__alloc();
__split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
@@ -1582,8 +1507,6 @@ vector<_Tp, _Allocator>::push_back(const_reference __x)
__push_back_slow_path(__x);
}
-#ifndef _LIBCPP_CXX03_LANG
-
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
void
@@ -1631,8 +1554,6 @@ vector<_Tp, _Allocator>::emplace_back(_Args&&... __args)
#endif
}
-#endif // !_LIBCPP_CXX03_LANG
-
template <class _Tp, class _Allocator>
inline
void
@@ -1655,7 +1576,7 @@ vector<_Tp, _Allocator>::erase(const_iterator __position)
pointer __p = this->__begin_ + __ps;
this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p));
this->__invalidate_iterators_past(__p-1);
- iterator __r = __make_iter(__p);
+ iterator __r = iterator(this, __p);
return __r;
}
@@ -1674,7 +1595,7 @@ vector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last)
this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p));
this->__invalidate_iterators_past(__p - 1);
}
- iterator __r = __make_iter(__p);
+ iterator __r = iterator(this, __p);
return __r;
}
@@ -1726,11 +1647,9 @@ vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x)
__v.push_back(__x);
__p = __swap_out_circular_buffer(__v, __p);
}
- return __make_iter(__p);
+ return iterator(this, __p);
}
-#ifndef _LIBCPP_CXX03_LANG
-
template <class _Tp, class _Allocator>
typename vector<_Tp, _Allocator>::iterator
vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x)
@@ -1757,7 +1676,7 @@ vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x)
__v.push_back(_VSTD::move(__x));
__p = __swap_out_circular_buffer(__v, __p);
}
- return __make_iter(__p);
+ return iterator(this, __p);
}
template <class _Tp, class _Allocator>
@@ -1788,11 +1707,9 @@ vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args)
__v.emplace_back(_VSTD::forward<_Args>(__args)...);
__p = __swap_out_circular_buffer(__v, __p);
}
- return __make_iter(__p);
+ return iterator(this, __p);
}
-#endif // !_LIBCPP_CXX03_LANG
-
template <class _Tp, class _Allocator>
typename vector<_Tp, _Allocator>::iterator
vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x)
@@ -1829,7 +1746,7 @@ vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_
__p = __swap_out_circular_buffer(__v, __p);
}
}
- return __make_iter(__p);
+ return iterator(this, __p);
}
template <class _Tp, class _Allocator>
@@ -1872,14 +1789,14 @@ vector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __firs
}
catch (...)
{
- erase(__make_iter(__old_last), end());
+ erase(iterator(this, __old_last), end());
throw;
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
__p = _VSTD::rotate(__p, __old_last, this->__end_);
- insert(__make_iter(__p), _VSTD::make_move_iterator(__v.begin()),
- _VSTD::make_move_iterator(__v.end()));
+ insert(iterator(this, __p), _VSTD::make_move_iterator(__v.begin()),
+ _VSTD::make_move_iterator(__v.end()));
return begin() + __off;
}
@@ -1929,7 +1846,7 @@ vector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __fi
__p = __swap_out_circular_buffer(__v, __p);
}
}
- return __make_iter(__p);
+ return iterator(this, __p);
}
template <class _Tp, class _Allocator>
@@ -1973,9 +1890,7 @@ vector<_Tp, _Allocator>::swap(vector& __x)
_VSTD::swap(this->__end_cap(), __x.__end_cap());
_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, _VSTD::addressof(__x));
-#endif
+ std::__debug_db_swap(this, std::addressof(__x));
}
template <class _Tp, class _Allocator>
@@ -1999,7 +1914,7 @@ vector<_Tp, _Allocator>::__invariants() const
return true;
}
-#if _LIBCPP_DEBUG_LEVEL == 2
+#ifdef _LIBCPP_ENABLE_DEBUG_MODE
template <class _Tp, class _Allocator>
bool
@@ -2031,24 +1946,13 @@ vector<_Tp, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __
return this->__begin_ <= __p && __p < this->__end_;
}
-#endif // _LIBCPP_DEBUG_LEVEL == 2
-
-template <class _Tp, class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
-void
-vector<_Tp, _Allocator>::__invalidate_all_iterators()
-{
-#if _LIBCPP_DEBUG_LEVEL == 2
- __get_db()->__invalidate_all(this);
-#endif
-}
-
+#endif // _LIBCPP_ENABLE_DEBUG_MODE
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
void
vector<_Tp, _Allocator>::__invalidate_iterators_past(pointer __new_last) {
-#if _LIBCPP_DEBUG_LEVEL == 2
+#ifdef _LIBCPP_ENABLE_DEBUG_MODE
__c_node* __c = __get_db()->__find_c_and_lock(this);
for (__i_node** __p = __c->end_; __p != __c->beg_; ) {
--__p;
@@ -2079,7 +1983,6 @@ struct __has_storage_type<vector<bool, _Allocator> >
template <class _Allocator>
class _LIBCPP_TEMPLATE_VIS vector<bool, _Allocator>
- : private __vector_base_common<true>
{
public:
typedef vector __self;
@@ -2107,7 +2010,11 @@ private:
__compressed_pair<size_type, __storage_allocator> __cap_alloc_;
public:
typedef __bit_reference<vector> reference;
+#ifdef _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL
+ using const_reference = bool;
+#else
typedef __bit_const_reference<vector> const_reference;
+#endif
private:
_LIBCPP_INLINE_VISIBILITY
size_type& __cap() _NOEXCEPT
@@ -2172,23 +2079,23 @@ public:
vector(initializer_list<value_type> __il, const allocator_type& __a);
_LIBCPP_INLINE_VISIBILITY
+ vector& operator=(initializer_list<value_type> __il)
+ {assign(__il.begin(), __il.end()); return *this;}
+
+#endif // !_LIBCPP_CXX03_LANG
+
+ _LIBCPP_INLINE_VISIBILITY
vector(vector&& __v)
#if _LIBCPP_STD_VER > 14
- _NOEXCEPT;
+ noexcept;
#else
_NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
#endif
- vector(vector&& __v, const __identity_t<allocator_type>& __a);
+ vector(vector&& __v, const __type_identity_t<allocator_type>& __a);
_LIBCPP_INLINE_VISIBILITY
vector& operator=(vector&& __v)
_NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
- _LIBCPP_INLINE_VISIBILITY
- vector& operator=(initializer_list<value_type> __il)
- {assign(__il.begin(), __il.end()); return *this;}
-
-#endif // !_LIBCPP_CXX03_LANG
-
template <class _InputIterator>
typename enable_if
<
@@ -2304,7 +2211,6 @@ public:
iterator insert(const_iterator __position, const value_type& __x);
iterator insert(const_iterator __position, size_type __n, const value_type& __x);
- iterator insert(const_iterator __position, size_type __n, const_reference __x);
template <class _InputIterator>
typename enable_if
<
@@ -2348,12 +2254,36 @@ public:
bool __invariants() const;
private:
- _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
- void __vallocate(size_type __n);
+ _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
+ void __throw_length_error() const {
+ _VSTD::__throw_length_error("vector");
+ }
+
+ _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
+ void __throw_out_of_range() const {
+ _VSTD::__throw_out_of_range("vector");
+ }
+
+ // Allocate space for __n objects
+ // throws length_error if __n > max_size()
+ // throws (probably bad_alloc) if memory run out
+ // Precondition: __begin_ == __end_ == __cap() == 0
+ // Precondition: __n > 0
+ // Postcondition: capacity() >= __n
+ // Postcondition: size() == 0
+ _LIBCPP_HIDE_FROM_ABI void __vallocate(size_type __n) {
+ if (__n > max_size())
+ __throw_length_error();
+ auto __allocation = std::__allocate_at_least(__alloc(), __external_cap_to_internal(__n));
+ __begin_ = __allocation.ptr;
+ __size_ = 0;
+ __cap() = __allocation.count;
+ }
+
void __vdeallocate() _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
static size_type __align_it(size_type __new_size) _NOEXCEPT
- {return __new_size + (__bits_per_word-1) & ~((size_type)__bits_per_word-1);}
+ {return (__new_size + (__bits_per_word-1)) & ~((size_type)__bits_per_word-1);}
_LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
_LIBCPP_INLINE_VISIBILITY void __construct_at_end(size_type __n, bool __x);
template <class _ForwardIterator>
@@ -2368,8 +2298,10 @@ private:
reference __make_ref(size_type __pos) _NOEXCEPT
{return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
_LIBCPP_INLINE_VISIBILITY
- const_reference __make_ref(size_type __pos) const _NOEXCEPT
- {return const_reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
+ const_reference __make_ref(size_type __pos) const _NOEXCEPT {
+ return __bit_const_reference<vector>(__begin_ + __pos / __bits_per_word,
+ __storage_type(1) << __pos % __bits_per_word);
+ }
_LIBCPP_INLINE_VISIBILITY
iterator __make_iter(size_type __pos) _NOEXCEPT
{return iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
@@ -2429,39 +2361,13 @@ private:
};
template <class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
-void
-vector<bool, _Allocator>::__invalidate_all_iterators()
-{
-}
-
-// Allocate space for __n objects
-// throws length_error if __n > max_size()
-// throws (probably bad_alloc) if memory run out
-// Precondition: __begin_ == __end_ == __cap() == 0
-// Precondition: __n > 0
-// Postcondition: capacity() == __n
-// Postcondition: size() == 0
-template <class _Allocator>
-void
-vector<bool, _Allocator>::__vallocate(size_type __n)
-{
- if (__n > max_size())
- this->__throw_length_error();
- __n = __external_cap_to_internal(__n);
- this->__begin_ = __storage_traits::allocate(this->__alloc(), __n);
- this->__size_ = 0;
- this->__cap() = __n;
-}
-
-template <class _Allocator>
void
vector<bool, _Allocator>::__vdeallocate() _NOEXCEPT
{
if (this->__begin_ != nullptr)
{
__storage_traits::deallocate(this->__alloc(), this->__begin_, __cap());
- __invalidate_all_iterators();
+ std::__debug_db_invalidate_all(this);
this->__begin_ = nullptr;
this->__size_ = this->__cap() = 0;
}
@@ -2634,7 +2540,7 @@ vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
{
if (__begin_ != nullptr)
__storage_traits::deallocate(__alloc(), __begin_, __cap());
- __invalidate_all_iterators();
+ std::__debug_db_invalidate_all(this);
throw;
}
#endif // _LIBCPP_NO_EXCEPTIONS
@@ -2661,7 +2567,7 @@ vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
{
if (__begin_ != nullptr)
__storage_traits::deallocate(__alloc(), __begin_, __cap());
- __invalidate_all_iterators();
+ std::__debug_db_invalidate_all(this);
throw;
}
#endif // _LIBCPP_NO_EXCEPTIONS
@@ -2736,7 +2642,7 @@ vector<bool, _Allocator>::~vector()
{
if (__begin_ != nullptr)
__storage_traits::deallocate(__alloc(), __begin_, __cap());
- __invalidate_all_iterators();
+ std::__debug_db_invalidate_all(this);
}
template <class _Allocator>
@@ -2786,8 +2692,6 @@ vector<bool, _Allocator>::operator=(const vector& __v)
return *this;
}
-#ifndef _LIBCPP_CXX03_LANG
-
template <class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY vector<bool, _Allocator>::vector(vector&& __v)
#if _LIBCPP_STD_VER > 14
@@ -2804,7 +2708,7 @@ inline _LIBCPP_INLINE_VISIBILITY vector<bool, _Allocator>::vector(vector&& __v)
}
template <class _Allocator>
-vector<bool, _Allocator>::vector(vector&& __v, const __identity_t<allocator_type>& __a)
+vector<bool, _Allocator>::vector(vector&& __v, const __type_identity_t<allocator_type>& __a)
: __begin_(nullptr),
__size_(0),
__cap_alloc_(0, __a)
@@ -2859,8 +2763,6 @@ vector<bool, _Allocator>::__move_assign(vector& __c, true_type)
__c.__cap() = __c.__size_ = 0;
}
-#endif // !_LIBCPP_CXX03_LANG
-
template <class _Allocator>
void
vector<bool, _Allocator>::assign(size_type __n, const value_type& __x)
@@ -2880,7 +2782,7 @@ vector<bool, _Allocator>::assign(size_type __n, const value_type& __x)
}
_VSTD::fill_n(begin(), __n, __x);
}
- __invalidate_all_iterators();
+ std::__debug_db_invalidate_all(this);
}
template <class _Allocator>
@@ -2934,7 +2836,7 @@ vector<bool, _Allocator>::reserve(size_type __n)
__v.__vallocate(__n);
__v.__construct_at_end(this->begin(), this->end());
swap(__v);
- __invalidate_all_iterators();
+ std::__debug_db_invalidate_all(this);
}
}
@@ -3243,7 +3145,7 @@ vector<bool, _Allocator>::__hash_code() const _NOEXCEPT
template <class _Allocator>
struct _LIBCPP_TEMPLATE_VIS hash<vector<bool, _Allocator> >
- : public unary_function<vector<bool, _Allocator>, size_t>
+ : public __unary_function<vector<bool, _Allocator>, size_t>
{
_LIBCPP_INLINE_VISIBILITY
size_t operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT
@@ -3324,8 +3226,16 @@ erase_if(vector<_Tp, _Allocator>& __c, _Predicate __pred) {
__c.erase(_VSTD::remove_if(__c.begin(), __c.end(), __pred), __c.end());
return __old_size - __c.size();
}
+
+template <>
+inline constexpr bool __format::__enable_insertable<std::vector<char>> = true;
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+template <>
+inline constexpr bool __format::__enable_insertable<std::vector<wchar_t>> = true;
#endif
+#endif // _LIBCPP_STD_VER > 17
+
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS