aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/libcxx/include/vector
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/libcxx/include/vector')
-rw-r--r--contrib/llvm-project/libcxx/include/vector163
1 files changed, 74 insertions, 89 deletions
diff --git a/contrib/llvm-project/libcxx/include/vector b/contrib/llvm-project/libcxx/include/vector
index 139e4d13c1e7..d010a1f6ec9f 100644
--- a/contrib/llvm-project/libcxx/include/vector
+++ b/contrib/llvm-project/libcxx/include/vector
@@ -10,6 +10,8 @@
#ifndef _LIBCPP_VECTOR
#define _LIBCPP_VECTOR
+// clang-format off
+
/*
vector synopsis
@@ -301,6 +303,8 @@ template<class T, class charT> requires is-vector-bool-reference<T> // Since C++
*/
+// clang-format on
+
#include <__algorithm/copy.h>
#include <__algorithm/equal.h>
#include <__algorithm/fill_n.h>
@@ -833,11 +837,11 @@ private:
template <class _Up>
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
- inline void __push_back_slow_path(_Up&& __x);
+ inline pointer __push_back_slow_path(_Up&& __x);
template <class... _Args>
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
- inline void __emplace_back_slow_path(_Args&&... __args);
+ inline pointer __emplace_back_slow_path(_Args&&... __args);
// The following functions are no-ops outside of AddressSanitizer mode.
// We call annotations for every allocator, unless explicitly disabled.
@@ -846,20 +850,23 @@ private:
// __asan_annotate_container_with_allocator to false.
// For more details, see the "Using libc++" documentation page or
// the documentation for __sanitizer_annotate_contiguous_container.
-#ifndef _LIBCPP_HAS_NO_ASAN
- _LIBCPP_CONSTEXPR_SINCE_CXX20
- void __annotate_contiguous_container(const void *__beg, const void *__end,
+
+ _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
+ void __annotate_contiguous_container(const void *__beg,
+ const void *__end,
const void *__old_mid,
const void *__new_mid) const
{
+ (void)__beg;
+ (void)__end;
+ (void)__old_mid;
+ (void)__new_mid;
+#ifndef _LIBCPP_HAS_NO_ASAN
if (!__libcpp_is_constant_evaluated() && __beg != nullptr && __asan_annotate_container_with_allocator<_Allocator>::value)
__sanitizer_annotate_contiguous_container(__beg, __end, __old_mid, __new_mid);
- }
-#else
- _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
- void __annotate_contiguous_container(const void*, const void*, const void*,
- const void*) const _NOEXCEPT {}
#endif
+ }
+
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
void __annotate_new(size_type __current_size) const _NOEXCEPT {
__annotate_contiguous_container(data(), data() + capacity(),
@@ -1609,7 +1616,7 @@ vector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT
template <class _Tp, class _Allocator>
template <class _Up>
_LIBCPP_CONSTEXPR_SINCE_CXX20
-void
+typename vector<_Tp, _Allocator>::pointer
vector<_Tp, _Allocator>::__push_back_slow_path(_Up&& __x)
{
allocator_type& __a = this->__alloc();
@@ -1618,6 +1625,7 @@ vector<_Tp, _Allocator>::__push_back_slow_path(_Up&& __x)
__alloc_traits::construct(__a, std::__to_address(__v.__end_), std::forward<_Up>(__x));
__v.__end_++;
__swap_out_circular_buffer(__v);
+ return this->__end_;
}
template <class _Tp, class _Allocator>
@@ -1626,12 +1634,14 @@ inline _LIBCPP_HIDE_FROM_ABI
void
vector<_Tp, _Allocator>::push_back(const_reference __x)
{
- if (this->__end_ != this->__end_cap())
- {
+ pointer __end = this->__end_;
+ if (__end < this->__end_cap()) {
__construct_one_at_end(__x);
+ ++__end;
+ } else {
+ __end = __push_back_slow_path(__x);
}
- else
- __push_back_slow_path(__x);
+ this->__end_ = __end;
}
template <class _Tp, class _Allocator>
@@ -1640,18 +1650,20 @@ inline _LIBCPP_HIDE_FROM_ABI
void
vector<_Tp, _Allocator>::push_back(value_type&& __x)
{
- if (this->__end_ < this->__end_cap())
- {
+ pointer __end = this->__end_;
+ if (__end < this->__end_cap()) {
__construct_one_at_end(std::move(__x));
+ ++__end;
+ } else {
+ __end = __push_back_slow_path(std::move(__x));
}
- else
- __push_back_slow_path(std::move(__x));
+ this->__end_ = __end;
}
template <class _Tp, class _Allocator>
template <class... _Args>
_LIBCPP_CONSTEXPR_SINCE_CXX20
-void
+typename vector<_Tp, _Allocator>::pointer
vector<_Tp, _Allocator>::__emplace_back_slow_path(_Args&&... __args)
{
allocator_type& __a = this->__alloc();
@@ -1660,6 +1672,7 @@ vector<_Tp, _Allocator>::__emplace_back_slow_path(_Args&&... __args)
__alloc_traits::construct(__a, std::__to_address(__v.__end_), std::forward<_Args>(__args)...);
__v.__end_++;
__swap_out_circular_buffer(__v);
+ return this->__end_;
}
template <class _Tp, class _Allocator>
@@ -1673,14 +1686,16 @@ void
#endif
vector<_Tp, _Allocator>::emplace_back(_Args&&... __args)
{
- if (this->__end_ < this->__end_cap())
- {
+ pointer __end = this->__end_;
+ if (__end < this->__end_cap()) {
__construct_one_at_end(std::forward<_Args>(__args)...);
+ ++__end;
+ } else {
+ __end = __emplace_back_slow_path(std::forward<_Args>(__args)...);
}
- else
- __emplace_back_slow_path(std::forward<_Args>(__args)...);
+ this->__end_ = __end;
#if _LIBCPP_STD_VER >= 17
- return this->back();
+ return *(__end - 1);
#endif
}
@@ -2142,18 +2157,14 @@ public:
#endif
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(size_type __n, const value_type& __v);
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(size_type __n, const value_type& __v, const allocator_type& __a);
- template <class _InputIterator>
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(_InputIterator __first, _InputIterator __last,
- typename enable_if<__has_exactly_input_iterator_category<_InputIterator>::value>::type* = 0);
- template <class _InputIterator>
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
- typename enable_if<__has_exactly_input_iterator_category<_InputIterator>::value>::type* = 0);
- template <class _ForwardIterator>
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(_ForwardIterator __first, _ForwardIterator __last,
- typename enable_if<__has_forward_iterator_category<_ForwardIterator>::value>::type* = 0);
- template <class _ForwardIterator>
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
- typename enable_if<__has_forward_iterator_category<_ForwardIterator>::value>::type* = 0);
+ template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> = 0>
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(_InputIterator __first, _InputIterator __last);
+ template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> = 0>
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
+ template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0>
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(_ForwardIterator __first, _ForwardIterator __last);
+ template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0>
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a);
#if _LIBCPP_STD_VER >= 23
template <_ContainerCompatibleRange<bool> _Range>
@@ -2198,17 +2209,11 @@ public:
vector& operator=(vector&& __v)
_NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
- template <class _InputIterator>
- typename enable_if <__has_exactly_input_iterator_category<_InputIterator>::value,
- void
- >::type
+ template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> = 0>
+ void
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 assign(_InputIterator __first, _InputIterator __last);
- template <class _ForwardIterator>
- typename enable_if
- <
- __has_forward_iterator_category<_ForwardIterator>::value,
- void
- >::type
+ template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0>
+ void
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 assign(_ForwardIterator __first, _ForwardIterator __last);
#if _LIBCPP_STD_VER >= 23
@@ -2332,17 +2337,11 @@ public:
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator insert(const_iterator __position, const value_type& __x);
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator insert(const_iterator __position, size_type __n, const value_type& __x);
- template <class _InputIterator>
- typename enable_if <__has_exactly_input_iterator_category<_InputIterator>::value,
- iterator
- >::type
+ template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> = 0>
+ iterator
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
- template <class _ForwardIterator>
- typename enable_if
- <
- __has_forward_iterator_category<_ForwardIterator>::value,
- iterator
- >::type
+ template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0>
+ iterator
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
#if _LIBCPP_STD_VER >= 23
@@ -2697,10 +2696,9 @@ vector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const all
}
template <class _Allocator>
-template <class _InputIterator>
+template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> >
_LIBCPP_CONSTEXPR_SINCE_CXX20
-vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
- typename enable_if<__has_exactly_input_iterator_category<_InputIterator>::value>::type*)
+vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last)
: __begin_(nullptr),
__size_(0),
__cap_alloc_(0, __default_init_tag())
@@ -2709,10 +2707,9 @@ vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
}
template <class _Allocator>
-template <class _InputIterator>
+template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> >
_LIBCPP_CONSTEXPR_SINCE_CXX20
-vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
- typename enable_if<__has_exactly_input_iterator_category<_InputIterator>::value>::type*)
+vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a)
: __begin_(nullptr),
__size_(0),
__cap_alloc_(0, static_cast<__storage_allocator>(__a))
@@ -2721,10 +2718,9 @@ vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
}
template <class _Allocator>
-template <class _ForwardIterator>
+template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> >
_LIBCPP_CONSTEXPR_SINCE_CXX20
-vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last,
- typename enable_if<__has_forward_iterator_category<_ForwardIterator>::value>::type*)
+vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last)
: __begin_(nullptr),
__size_(0),
__cap_alloc_(0, __default_init_tag())
@@ -2734,10 +2730,9 @@ vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __la
}
template <class _Allocator>
-template <class _ForwardIterator>
+template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> >
_LIBCPP_CONSTEXPR_SINCE_CXX20
-vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
- typename enable_if<__has_forward_iterator_category<_ForwardIterator>::value>::type*)
+vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a)
: __begin_(nullptr),
__size_(0),
__cap_alloc_(0, static_cast<__storage_allocator>(__a))
@@ -2924,10 +2919,9 @@ vector<bool, _Allocator>::assign(size_type __n, const value_type& __x)
}
template <class _Allocator>
-template <class _InputIterator>
-_LIBCPP_CONSTEXPR_SINCE_CXX20 typename enable_if <__has_exactly_input_iterator_category<_InputIterator>::value,
- void
->::type
+template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> >
+_LIBCPP_CONSTEXPR_SINCE_CXX20
+void
vector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
{
__assign_with_sentinel(__first, __last);
@@ -2943,13 +2937,9 @@ void vector<bool, _Allocator>::__assign_with_sentinel(_Iterator __first, _Sentin
}
template <class _Allocator>
-template <class _ForwardIterator>
+template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> >
_LIBCPP_CONSTEXPR_SINCE_CXX20
-typename enable_if
-<
- __has_forward_iterator_category<_ForwardIterator>::value,
- void
->::type
+void
vector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
{
__assign_with_size(__first, __last, std::distance(__first, __last));
@@ -3090,10 +3080,9 @@ vector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const
}
template <class _Allocator>
-template <class _InputIterator>
-_LIBCPP_CONSTEXPR_SINCE_CXX20 typename enable_if <__has_exactly_input_iterator_category<_InputIterator>::value,
- typename vector<bool, _Allocator>::iterator
->::type
+template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> >
+_LIBCPP_CONSTEXPR_SINCE_CXX20
+typename vector<bool, _Allocator>::iterator
vector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
{
return __insert_with_sentinel(__position, __first, __last);
@@ -3140,13 +3129,9 @@ vector<bool, _Allocator>::__insert_with_sentinel(const_iterator __position, _Inp
}
template <class _Allocator>
-template <class _ForwardIterator>
+template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> >
_LIBCPP_CONSTEXPR_SINCE_CXX20
-typename enable_if
-<
- __has_forward_iterator_category<_ForwardIterator>::value,
- typename vector<bool, _Allocator>::iterator
->::type
+typename vector<bool, _Allocator>::iterator
vector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
{
return __insert_with_size(__position, __first, __last, std::distance(__first, __last));