diff options
Diffstat (limited to 'contrib/llvm-project/libcxx/include/__memory/uninitialized_algorithms.h')
| -rw-r--r-- | contrib/llvm-project/libcxx/include/__memory/uninitialized_algorithms.h | 149 |
1 files changed, 78 insertions, 71 deletions
diff --git a/contrib/llvm-project/libcxx/include/__memory/uninitialized_algorithms.h b/contrib/llvm-project/libcxx/include/__memory/uninitialized_algorithms.h index 2b68df8e6d63..b0eb7001598b 100644 --- a/contrib/llvm-project/libcxx/include/__memory/uninitialized_algorithms.h +++ b/contrib/llvm-project/libcxx/include/__memory/uninitialized_algorithms.h @@ -44,35 +44,32 @@ _LIBCPP_BEGIN_NAMESPACE_STD -// This is a simplified version of C++20 `unreachable_sentinel` that doesn't use concepts and thus can be used in any -// language mode. -struct __unreachable_sentinel { - template <class _Iter> - _LIBCPP_HIDE_FROM_ABI friend _LIBCPP_CONSTEXPR bool operator!=(const _Iter&, __unreachable_sentinel) _NOEXCEPT { - return true; +struct __always_false { + template <class... _Args> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool operator()(_Args&&...) const _NOEXCEPT { + return false; } }; // uninitialized_copy -template <class _ValueType, class _InputIterator, class _Sentinel1, class _ForwardIterator, class _Sentinel2> -inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator> -__uninitialized_copy(_InputIterator __ifirst, _Sentinel1 __ilast, - _ForwardIterator __ofirst, _Sentinel2 __olast) { +template <class _ValueType, class _InputIterator, class _Sentinel1, class _ForwardIterator, class _EndPredicate> +inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator> __uninitialized_copy( + _InputIterator __ifirst, _Sentinel1 __ilast, _ForwardIterator __ofirst, _EndPredicate __stop_copying) { _ForwardIterator __idx = __ofirst; #ifndef _LIBCPP_HAS_NO_EXCEPTIONS try { #endif - for (; __ifirst != __ilast && __idx != __olast; ++__ifirst, (void)++__idx) - ::new (_VSTD::__voidify(*__idx)) _ValueType(*__ifirst); + for (; __ifirst != __ilast && !__stop_copying(__idx); ++__ifirst, (void)++__idx) + ::new (std::__voidify(*__idx)) _ValueType(*__ifirst); #ifndef _LIBCPP_HAS_NO_EXCEPTIONS } catch (...) { - _VSTD::__destroy(__ofirst, __idx); + std::__destroy(__ofirst, __idx); throw; } #endif - return pair<_InputIterator, _ForwardIterator>(_VSTD::move(__ifirst), _VSTD::move(__idx)); + return pair<_InputIterator, _ForwardIterator>(std::move(__ifirst), std::move(__idx)); } template <class _InputIterator, class _ForwardIterator> @@ -80,40 +77,39 @@ _LIBCPP_HIDE_FROM_ABI _ForwardIterator uninitialized_copy(_InputIterator __ifirst, _InputIterator __ilast, _ForwardIterator __ofirst) { typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType; - auto __result = _VSTD::__uninitialized_copy<_ValueType>(_VSTD::move(__ifirst), _VSTD::move(__ilast), - _VSTD::move(__ofirst), __unreachable_sentinel()); - return _VSTD::move(__result.second); + auto __result = std::__uninitialized_copy<_ValueType>( + std::move(__ifirst), std::move(__ilast), std::move(__ofirst), __always_false()); + return std::move(__result.second); } // uninitialized_copy_n -template <class _ValueType, class _InputIterator, class _Size, class _ForwardIterator, class _Sentinel> -inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator> -__uninitialized_copy_n(_InputIterator __ifirst, _Size __n, - _ForwardIterator __ofirst, _Sentinel __olast) { +template <class _ValueType, class _InputIterator, class _Size, class _ForwardIterator, class _EndPredicate> +inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator> __uninitialized_copy_n( + _InputIterator __ifirst, _Size __n, _ForwardIterator __ofirst, _EndPredicate __stop_copying) { _ForwardIterator __idx = __ofirst; #ifndef _LIBCPP_HAS_NO_EXCEPTIONS try { #endif - for (; __n > 0 && __idx != __olast; ++__ifirst, (void)++__idx, (void)--__n) - ::new (_VSTD::__voidify(*__idx)) _ValueType(*__ifirst); + for (; __n > 0 && !__stop_copying(__idx); ++__ifirst, (void)++__idx, (void)--__n) + ::new (std::__voidify(*__idx)) _ValueType(*__ifirst); #ifndef _LIBCPP_HAS_NO_EXCEPTIONS } catch (...) { - _VSTD::__destroy(__ofirst, __idx); + std::__destroy(__ofirst, __idx); throw; } #endif - return pair<_InputIterator, _ForwardIterator>(_VSTD::move(__ifirst), _VSTD::move(__idx)); + return pair<_InputIterator, _ForwardIterator>(std::move(__ifirst), std::move(__idx)); } template <class _InputIterator, class _Size, class _ForwardIterator> inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator uninitialized_copy_n(_InputIterator __ifirst, _Size __n, _ForwardIterator __ofirst) { typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType; - auto __result = _VSTD::__uninitialized_copy_n<_ValueType>(_VSTD::move(__ifirst), __n, _VSTD::move(__ofirst), - __unreachable_sentinel()); - return _VSTD::move(__result.second); + auto __result = + std::__uninitialized_copy_n<_ValueType>(std::move(__ifirst), __n, std::move(__ofirst), __always_false()); + return std::move(__result.second); } // uninitialized_fill @@ -128,12 +124,12 @@ _ForwardIterator __uninitialized_fill(_ForwardIterator __first, _Sentinel __last { #endif for (; __idx != __last; ++__idx) - ::new (_VSTD::__voidify(*__idx)) _ValueType(__x); + ::new (std::__voidify(*__idx)) _ValueType(__x); #ifndef _LIBCPP_HAS_NO_EXCEPTIONS } catch (...) { - _VSTD::__destroy(__first, __idx); + std::__destroy(__first, __idx); throw; } #endif @@ -146,7 +142,7 @@ inline _LIBCPP_HIDE_FROM_ABI void uninitialized_fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __x) { typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType; - (void)_VSTD::__uninitialized_fill<_ValueType>(__first, __last, __x); + (void)std::__uninitialized_fill<_ValueType>(__first, __last, __x); } // uninitialized_fill_n @@ -161,12 +157,12 @@ _ForwardIterator __uninitialized_fill_n(_ForwardIterator __first, _Size __n, con { #endif for (; __n > 0; ++__idx, (void) --__n) - ::new (_VSTD::__voidify(*__idx)) _ValueType(__x); + ::new (std::__voidify(*__idx)) _ValueType(__x); #ifndef _LIBCPP_HAS_NO_EXCEPTIONS } catch (...) { - _VSTD::__destroy(__first, __idx); + std::__destroy(__first, __idx); throw; } #endif @@ -179,7 +175,7 @@ inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator uninitialized_fill_n(_ForwardIterator __first, _Size __n, const _Tp& __x) { typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType; - return _VSTD::__uninitialized_fill_n<_ValueType>(__first, __n, __x); + return std::__uninitialized_fill_n<_ValueType>(__first, __n, __x); } #if _LIBCPP_STD_VER >= 17 @@ -194,10 +190,10 @@ _ForwardIterator __uninitialized_default_construct(_ForwardIterator __first, _Se try { #endif for (; __idx != __last; ++__idx) - ::new (_VSTD::__voidify(*__idx)) _ValueType; + ::new (std::__voidify(*__idx)) _ValueType; #ifndef _LIBCPP_HAS_NO_EXCEPTIONS } catch (...) { - _VSTD::__destroy(__first, __idx); + std::__destroy(__first, __idx); throw; } #endif @@ -209,8 +205,8 @@ template <class _ForwardIterator> inline _LIBCPP_HIDE_FROM_ABI void uninitialized_default_construct(_ForwardIterator __first, _ForwardIterator __last) { using _ValueType = typename iterator_traits<_ForwardIterator>::value_type; - (void)_VSTD::__uninitialized_default_construct<_ValueType>( - _VSTD::move(__first), _VSTD::move(__last)); + (void)std::__uninitialized_default_construct<_ValueType>( + std::move(__first), std::move(__last)); } // uninitialized_default_construct_n @@ -223,10 +219,10 @@ _ForwardIterator __uninitialized_default_construct_n(_ForwardIterator __first, _ try { #endif for (; __n > 0; ++__idx, (void) --__n) - ::new (_VSTD::__voidify(*__idx)) _ValueType; + ::new (std::__voidify(*__idx)) _ValueType; #ifndef _LIBCPP_HAS_NO_EXCEPTIONS } catch (...) { - _VSTD::__destroy(__first, __idx); + std::__destroy(__first, __idx); throw; } #endif @@ -238,7 +234,7 @@ template <class _ForwardIterator, class _Size> inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator uninitialized_default_construct_n(_ForwardIterator __first, _Size __n) { using _ValueType = typename iterator_traits<_ForwardIterator>::value_type; - return _VSTD::__uninitialized_default_construct_n<_ValueType>(_VSTD::move(__first), __n); + return std::__uninitialized_default_construct_n<_ValueType>(std::move(__first), __n); } // uninitialized_value_construct @@ -251,10 +247,10 @@ _ForwardIterator __uninitialized_value_construct(_ForwardIterator __first, _Sent try { #endif for (; __idx != __last; ++__idx) - ::new (_VSTD::__voidify(*__idx)) _ValueType(); + ::new (std::__voidify(*__idx)) _ValueType(); #ifndef _LIBCPP_HAS_NO_EXCEPTIONS } catch (...) { - _VSTD::__destroy(__first, __idx); + std::__destroy(__first, __idx); throw; } #endif @@ -266,8 +262,8 @@ template <class _ForwardIterator> inline _LIBCPP_HIDE_FROM_ABI void uninitialized_value_construct(_ForwardIterator __first, _ForwardIterator __last) { using _ValueType = typename iterator_traits<_ForwardIterator>::value_type; - (void)_VSTD::__uninitialized_value_construct<_ValueType>( - _VSTD::move(__first), _VSTD::move(__last)); + (void)std::__uninitialized_value_construct<_ValueType>( + std::move(__first), std::move(__last)); } // uninitialized_value_construct_n @@ -280,10 +276,10 @@ _ForwardIterator __uninitialized_value_construct_n(_ForwardIterator __first, _Si try { #endif for (; __n > 0; ++__idx, (void) --__n) - ::new (_VSTD::__voidify(*__idx)) _ValueType(); + ::new (std::__voidify(*__idx)) _ValueType(); #ifndef _LIBCPP_HAS_NO_EXCEPTIONS } catch (...) { - _VSTD::__destroy(__first, __idx); + std::__destroy(__first, __idx); throw; } #endif @@ -295,74 +291,85 @@ template <class _ForwardIterator, class _Size> inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator uninitialized_value_construct_n(_ForwardIterator __first, _Size __n) { using _ValueType = typename iterator_traits<_ForwardIterator>::value_type; - return std::__uninitialized_value_construct_n<_ValueType>(_VSTD::move(__first), __n); + return std::__uninitialized_value_construct_n<_ValueType>(std::move(__first), __n); } // uninitialized_move -template <class _ValueType, class _InputIterator, class _Sentinel1, class _ForwardIterator, class _Sentinel2, +template <class _ValueType, + class _InputIterator, + class _Sentinel1, + class _ForwardIterator, + class _EndPredicate, class _IterMove> -inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator> -__uninitialized_move(_InputIterator __ifirst, _Sentinel1 __ilast, - _ForwardIterator __ofirst, _Sentinel2 __olast, _IterMove __iter_move) { +inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator> __uninitialized_move( + _InputIterator __ifirst, + _Sentinel1 __ilast, + _ForwardIterator __ofirst, + _EndPredicate __stop_moving, + _IterMove __iter_move) { auto __idx = __ofirst; #ifndef _LIBCPP_HAS_NO_EXCEPTIONS try { #endif - for (; __ifirst != __ilast && __idx != __olast; ++__idx, (void)++__ifirst) { - ::new (_VSTD::__voidify(*__idx)) _ValueType(__iter_move(__ifirst)); + for (; __ifirst != __ilast && !__stop_moving(__idx); ++__idx, (void)++__ifirst) { + ::new (std::__voidify(*__idx)) _ValueType(__iter_move(__ifirst)); } #ifndef _LIBCPP_HAS_NO_EXCEPTIONS } catch (...) { - _VSTD::__destroy(__ofirst, __idx); + std::__destroy(__ofirst, __idx); throw; } #endif - return {_VSTD::move(__ifirst), _VSTD::move(__idx)}; + return {std::move(__ifirst), std::move(__idx)}; } template <class _InputIterator, class _ForwardIterator> inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator uninitialized_move(_InputIterator __ifirst, _InputIterator __ilast, _ForwardIterator __ofirst) { using _ValueType = typename iterator_traits<_ForwardIterator>::value_type; - auto __iter_move = [](auto&& __iter) -> decltype(auto) { return _VSTD::move(*__iter); }; + auto __iter_move = [](auto&& __iter) -> decltype(auto) { return std::move(*__iter); }; - auto __result = _VSTD::__uninitialized_move<_ValueType>(_VSTD::move(__ifirst), _VSTD::move(__ilast), - _VSTD::move(__ofirst), __unreachable_sentinel(), __iter_move); - return _VSTD::move(__result.second); + auto __result = std::__uninitialized_move<_ValueType>( + std::move(__ifirst), std::move(__ilast), std::move(__ofirst), __always_false(), __iter_move); + return std::move(__result.second); } // uninitialized_move_n -template <class _ValueType, class _InputIterator, class _Size, class _ForwardIterator, class _Sentinel, class _IterMove> -inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator> -__uninitialized_move_n(_InputIterator __ifirst, _Size __n, - _ForwardIterator __ofirst, _Sentinel __olast, _IterMove __iter_move) { +template <class _ValueType, + class _InputIterator, + class _Size, + class _ForwardIterator, + class _EndPredicate, + class _IterMove> +inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator> __uninitialized_move_n( + _InputIterator __ifirst, _Size __n, _ForwardIterator __ofirst, _EndPredicate __stop_moving, _IterMove __iter_move) { auto __idx = __ofirst; #ifndef _LIBCPP_HAS_NO_EXCEPTIONS try { #endif - for (; __n > 0 && __idx != __olast; ++__idx, (void)++__ifirst, --__n) - ::new (_VSTD::__voidify(*__idx)) _ValueType(__iter_move(__ifirst)); + for (; __n > 0 && !__stop_moving(__idx); ++__idx, (void)++__ifirst, --__n) + ::new (std::__voidify(*__idx)) _ValueType(__iter_move(__ifirst)); #ifndef _LIBCPP_HAS_NO_EXCEPTIONS } catch (...) { - _VSTD::__destroy(__ofirst, __idx); + std::__destroy(__ofirst, __idx); throw; } #endif - return {_VSTD::move(__ifirst), _VSTD::move(__idx)}; + return {std::move(__ifirst), std::move(__idx)}; } template <class _InputIterator, class _Size, class _ForwardIterator> inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator> uninitialized_move_n(_InputIterator __ifirst, _Size __n, _ForwardIterator __ofirst) { using _ValueType = typename iterator_traits<_ForwardIterator>::value_type; - auto __iter_move = [](auto&& __iter) -> decltype(auto) { return _VSTD::move(*__iter); }; + auto __iter_move = [](auto&& __iter) -> decltype(auto) { return std::move(*__iter); }; - return _VSTD::__uninitialized_move_n<_ValueType>(_VSTD::move(__ifirst), __n, _VSTD::move(__ofirst), - __unreachable_sentinel(), __iter_move); + return std::__uninitialized_move_n<_ValueType>( + std::move(__ifirst), __n, std::move(__ofirst), __always_false(), __iter_move); } // TODO: Rewrite this to iterate left to right and use reverse_iterators when calling |
