summaryrefslogtreecommitdiff
path: root/include/vector
diff options
context:
space:
mode:
Diffstat (limited to 'include/vector')
-rw-r--r--include/vector141
1 files changed, 86 insertions, 55 deletions
diff --git a/include/vector b/include/vector
index 54b1e8831d5bc..0f5006f375671 100644
--- a/include/vector
+++ b/include/vector
@@ -244,6 +244,10 @@ public:
bool __invariants() const;
};
+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>;
+
template <class Allocator> struct hash<std::vector<bool, Allocator>>;
template <class T, class Allocator> bool operator==(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
@@ -291,7 +295,7 @@ template <bool>
class __vector_base_common
{
protected:
- _LIBCPP_ALWAYS_INLINE __vector_base_common() {}
+ _LIBCPP_INLINE_VISIBILITY __vector_base_common() {}
_LIBCPP_NORETURN void __throw_length_error() const;
_LIBCPP_NORETURN void __throw_out_of_range() const;
};
@@ -316,13 +320,14 @@ template <class _Tp, class _Allocator>
class __vector_base
: protected __vector_base_common<true>
{
-protected:
- typedef _Tp value_type;
+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::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;
@@ -350,6 +355,9 @@ protected:
__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
@@ -433,6 +441,15 @@ __vector_base<_Tp, _Allocator>::__vector_base(const allocator_type& __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, std::move(__a)) {}
+#endif
+
template <class _Tp, class _Allocator>
__vector_base<_Tp, _Allocator>::~__vector_base()
{
@@ -492,8 +509,8 @@ public:
#if _LIBCPP_STD_VER > 11
explicit vector(size_type __n, const allocator_type& __a);
#endif
- vector(size_type __n, const_reference __x);
- vector(size_type __n, const_reference __x, const allocator_type& __a);
+ vector(size_type __n, const value_type& __x);
+ vector(size_type __n, const value_type& __x, const allocator_type& __a);
template <class _InputIterator>
vector(_InputIterator __first,
typename enable_if<__is_input_iterator <_InputIterator>::value &&
@@ -776,8 +793,8 @@ public:
private:
_LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
_LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(pointer __new_last);
- void allocate(size_type __n);
- void deallocate() _NOEXCEPT;
+ void __vallocate(size_type __n);
+ void __vdeallocate() _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
void __construct_at_end(size_type __n);
_LIBCPP_INLINE_VISIBILITY
@@ -890,6 +907,22 @@ private:
};
+#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
+template<class _InputIterator,
+ class _Alloc = typename std::allocator<typename iterator_traits<_InputIterator>::value_type>,
+ class = typename enable_if<__is_allocator<_Alloc>::value, void>::type
+ >
+vector(_InputIterator, _InputIterator)
+ -> vector<typename iterator_traits<_InputIterator>::value_type, _Alloc>;
+
+template<class _InputIterator,
+ class _Alloc,
+ class = typename enable_if<__is_allocator<_Alloc>::value, void>::type
+ >
+vector(_InputIterator, _InputIterator, _Alloc)
+ -> vector<typename iterator_traits<_InputIterator>::value_type, _Alloc>;
+#endif
+
template <class _Tp, class _Allocator>
void
vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v)
@@ -930,7 +963,7 @@ vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, a
// Postcondition: size() == 0
template <class _Tp, class _Allocator>
void
-vector<_Tp, _Allocator>::allocate(size_type __n)
+vector<_Tp, _Allocator>::__vallocate(size_type __n)
{
if (__n > max_size())
this->__throw_length_error();
@@ -941,7 +974,7 @@ vector<_Tp, _Allocator>::allocate(size_type __n)
template <class _Tp, class _Allocator>
void
-vector<_Tp, _Allocator>::deallocate() _NOEXCEPT
+vector<_Tp, _Allocator>::__vdeallocate() _NOEXCEPT
{
if (this->__begin_ != nullptr)
{
@@ -1077,7 +1110,7 @@ vector<_Tp, _Allocator>::vector(size_type __n)
#endif
if (__n > 0)
{
- allocate(__n);
+ __vallocate(__n);
__construct_at_end(__n);
}
}
@@ -1092,27 +1125,27 @@ vector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a)
#endif
if (__n > 0)
{
- allocate(__n);
+ __vallocate(__n);
__construct_at_end(__n);
}
}
#endif
template <class _Tp, class _Allocator>
-vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x)
+vector<_Tp, _Allocator>::vector(size_type __n, const value_type& __x)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
if (__n > 0)
{
- allocate(__n);
+ __vallocate(__n);
__construct_at_end(__n, __x);
}
}
template <class _Tp, class _Allocator>
-vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x, const allocator_type& __a)
+vector<_Tp, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a)
: __base(__a)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
@@ -1120,7 +1153,7 @@ vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x, const alloca
#endif
if (__n > 0)
{
- allocate(__n);
+ __vallocate(__n);
__construct_at_end(__n, __x);
}
}
@@ -1174,7 +1207,7 @@ vector<_Tp, _Allocator>::vector(_ForwardIterator __first,
size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
if (__n > 0)
{
- allocate(__n);
+ __vallocate(__n);
__construct_at_end(__first, __last, __n);
}
}
@@ -1194,7 +1227,7 @@ vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __las
size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
if (__n > 0)
{
- allocate(__n);
+ __vallocate(__n);
__construct_at_end(__first, __last, __n);
}
}
@@ -1209,7 +1242,7 @@ vector<_Tp, _Allocator>::vector(const vector& __x)
size_type __n = __x.size();
if (__n > 0)
{
- allocate(__n);
+ __vallocate(__n);
__construct_at_end(__x.__begin_, __x.__end_, __n);
}
}
@@ -1224,7 +1257,7 @@ vector<_Tp, _Allocator>::vector(const vector& __x, const allocator_type& __a)
size_type __n = __x.size();
if (__n > 0)
{
- allocate(__n);
+ __vallocate(__n);
__construct_at_end(__x.__begin_, __x.__end_, __n);
}
}
@@ -1285,7 +1318,7 @@ vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il)
#endif
if (__il.size() > 0)
{
- allocate(__il.size());
+ __vallocate(__il.size());
__construct_at_end(__il.begin(), __il.end(), __il.size());
}
}
@@ -1300,7 +1333,7 @@ vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocat
#endif
if (__il.size() > 0)
{
- allocate(__il.size());
+ __vallocate(__il.size());
__construct_at_end(__il.begin(), __il.end(), __il.size());
}
}
@@ -1335,7 +1368,7 @@ void
vector<_Tp, _Allocator>::__move_assign(vector& __c, true_type)
_NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
{
- deallocate();
+ __vdeallocate();
__base::__move_assign_alloc(__c); // this can throw
this->__begin_ = __c.__begin_;
this->__end_ = __c.__end_;
@@ -1410,8 +1443,8 @@ vector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __las
}
else
{
- deallocate();
- allocate(__recommend(__new_size));
+ __vdeallocate();
+ __vallocate(__recommend(__new_size));
__construct_at_end(__first, __last, __new_size);
}
__invalidate_all_iterators();
@@ -1432,8 +1465,8 @@ vector<_Tp, _Allocator>::assign(size_type __n, const_reference __u)
}
else
{
- deallocate();
- allocate(__recommend(static_cast<size_type>(__n)));
+ __vdeallocate();
+ __vallocate(__recommend(static_cast<size_type>(__n)));
__construct_at_end(__n, __u);
}
__invalidate_all_iterators();
@@ -2416,8 +2449,8 @@ public:
private:
_LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
- void allocate(size_type __n);
- void deallocate() _NOEXCEPT;
+ void __vallocate(size_type __n);
+ 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);};
@@ -2455,7 +2488,7 @@ private:
void __copy_assign_alloc(const vector& __c, true_type)
{
if (__alloc() != __c.__alloc())
- deallocate();
+ __vdeallocate();
__alloc() = __c.__alloc();
}
@@ -2511,7 +2544,7 @@ vector<bool, _Allocator>::__invalidate_all_iterators()
// Postcondition: size() == 0
template <class _Allocator>
void
-vector<bool, _Allocator>::allocate(size_type __n)
+vector<bool, _Allocator>::__vallocate(size_type __n)
{
if (__n > max_size())
this->__throw_length_error();
@@ -2523,7 +2556,7 @@ vector<bool, _Allocator>::allocate(size_type __n)
template <class _Allocator>
void
-vector<bool, _Allocator>::deallocate() _NOEXCEPT
+vector<bool, _Allocator>::__vdeallocate() _NOEXCEPT
{
if (this->__begin_ != nullptr)
{
@@ -2620,7 +2653,7 @@ vector<bool, _Allocator>::vector(size_type __n)
{
if (__n > 0)
{
- allocate(__n);
+ __vallocate(__n);
__construct_at_end(__n, false);
}
}
@@ -2634,7 +2667,7 @@ vector<bool, _Allocator>::vector(size_type __n, const allocator_type& __a)
{
if (__n > 0)
{
- allocate(__n);
+ __vallocate(__n);
__construct_at_end(__n, false);
}
}
@@ -2648,7 +2681,7 @@ vector<bool, _Allocator>::vector(size_type __n, const value_type& __x)
{
if (__n > 0)
{
- allocate(__n);
+ __vallocate(__n);
__construct_at_end(__n, __x);
}
}
@@ -2661,7 +2694,7 @@ vector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const all
{
if (__n > 0)
{
- allocate(__n);
+ __vallocate(__n);
__construct_at_end(__n, __x);
}
}
@@ -2731,7 +2764,7 @@ vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __la
size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
if (__n > 0)
{
- allocate(__n);
+ __vallocate(__n);
__construct_at_end(__first, __last);
}
}
@@ -2747,7 +2780,7 @@ vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __la
size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
if (__n > 0)
{
- allocate(__n);
+ __vallocate(__n);
__construct_at_end(__first, __last);
}
}
@@ -2763,7 +2796,7 @@ vector<bool, _Allocator>::vector(initializer_list<value_type> __il)
size_type __n = static_cast<size_type>(__il.size());
if (__n > 0)
{
- allocate(__n);
+ __vallocate(__n);
__construct_at_end(__il.begin(), __il.end());
}
}
@@ -2777,7 +2810,7 @@ vector<bool, _Allocator>::vector(initializer_list<value_type> __il, const alloca
size_type __n = static_cast<size_type>(__il.size());
if (__n > 0)
{
- allocate(__n);
+ __vallocate(__n);
__construct_at_end(__il.begin(), __il.end());
}
}
@@ -2800,7 +2833,7 @@ vector<bool, _Allocator>::vector(const vector& __v)
{
if (__v.size() > 0)
{
- allocate(__v.size());
+ __vallocate(__v.size());
__construct_at_end(__v.begin(), __v.end());
}
}
@@ -2813,7 +2846,7 @@ vector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a)
{
if (__v.size() > 0)
{
- allocate(__v.size());
+ __vallocate(__v.size());
__construct_at_end(__v.begin(), __v.end());
}
}
@@ -2829,8 +2862,8 @@ vector<bool, _Allocator>::operator=(const vector& __v)
{
if (__v.__size_ > capacity())
{
- deallocate();
- allocate(__v.__size_);
+ __vdeallocate();
+ __vallocate(__v.__size_);
}
_VSTD::copy(__v.__begin_, __v.__begin_ + __external_cap_to_internal(__v.__size_), __begin_);
}
@@ -2842,17 +2875,15 @@ vector<bool, _Allocator>::operator=(const vector& __v)
#ifndef _LIBCPP_CXX03_LANG
template <class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
-vector<bool, _Allocator>::vector(vector&& __v)
+inline _LIBCPP_INLINE_VISIBILITY vector<bool, _Allocator>::vector(vector&& __v)
#if _LIBCPP_STD_VER > 14
- _NOEXCEPT
+ _NOEXCEPT
#else
- _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
+ _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
#endif
: __begin_(__v.__begin_),
__size_(__v.__size_),
- __cap_alloc_(__v.__cap_alloc_)
-{
+ __cap_alloc_(std::move(__v.__cap_alloc_)) {
__v.__begin_ = nullptr;
__v.__size_ = 0;
__v.__cap() = 0;
@@ -2874,7 +2905,7 @@ vector<bool, _Allocator>::vector(vector&& __v, const allocator_type& __a)
}
else if (__v.size() > 0)
{
- allocate(__v.size());
+ __vallocate(__v.size());
__construct_at_end(__v.begin(), __v.end());
}
}
@@ -2905,7 +2936,7 @@ void
vector<bool, _Allocator>::__move_assign(vector& __c, true_type)
_NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
{
- deallocate();
+ __vdeallocate();
__move_assign_alloc(__c);
this->__begin_ = __c.__begin_;
this->__size_ = __c.__size_;
@@ -2970,8 +3001,8 @@ vector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __la
{
if (__n > capacity())
{
- deallocate();
- allocate(__n);
+ __vdeallocate();
+ __vallocate(__n);
}
__construct_at_end(__first, __last);
}
@@ -2984,7 +3015,7 @@ vector<bool, _Allocator>::reserve(size_type __n)
if (__n > capacity())
{
vector __v(this->__alloc());
- __v.allocate(__n);
+ __v.__vallocate(__n);
__v.__construct_at_end(this->begin(), this->end());
swap(__v);
__invalidate_all_iterators();