From 2289036a40082eb5316e2a46fb2f3a78a8be0c7d Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 14 Feb 2020 10:34:21 -0500 Subject: update libcxx to llvm10.0.0rc2 --- lib/libcxx/include/algorithm | 114 +++++++++++++++++++++++++++---------------- 1 file changed, 73 insertions(+), 41 deletions(-) (limited to 'lib/libcxx/include/algorithm') diff --git a/lib/libcxx/include/algorithm b/lib/libcxx/include/algorithm index 0d78626755..83e49f19ab 100644 --- a/lib/libcxx/include/algorithm +++ b/lib/libcxx/include/algorithm @@ -167,20 +167,20 @@ template Size count, const T& value, BinaryPredicate pred); template - OutputIterator + constexpr OutputIterator // constexpr in C++20 copy(InputIterator first, InputIterator last, OutputIterator result); template - OutputIterator + constexpr OutputIterator // constexpr in C++20 copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred); template - OutputIterator + constexpr OutputIterator // constexpr in C++20 copy_n(InputIterator first, Size n, OutputIterator result); template - BidirectionalIterator2 + constexpr BidirectionalIterator2 // constexpr in C++20 copy_backward(BidirectionalIterator1 first, BidirectionalIterator1 last, BidirectionalIterator2 result); @@ -1631,7 +1631,7 @@ search_n(_ForwardIterator __first, _ForwardIterator __last, _Size __count, const // copy template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _Iter __unwrap_iter(_Iter __i) { @@ -1639,7 +1639,7 @@ __unwrap_iter(_Iter __i) } template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 typename enable_if < is_trivially_copy_assignable<_Tp>::value, @@ -1693,15 +1693,23 @@ __unwrap_iter(__wrap_iter<_Tp*> __i) #endif // _LIBCPP_DEBUG_LEVEL < 2 template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator -__copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result) +__copy_constexpr(_InputIterator __first, _InputIterator __last, _OutputIterator __result) { for (; __first != __last; ++__first, (void) ++__result) *__result = *__first; return __result; } +template +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +__copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result) +{ + return __copy_constexpr(__first, __last, __result); +} + template inline _LIBCPP_INLINE_VISIBILITY typename enable_if @@ -1719,25 +1727,39 @@ __copy(_Tp* __first, _Tp* __last, _Up* __result) } template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17_WITH_IS_CONSTANT_EVALUATED _OutputIterator copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result) { - return _VSTD::__copy(__unwrap_iter(__first), __unwrap_iter(__last), __unwrap_iter(__result)); + if (__libcpp_is_constant_evaluated()) { + return _VSTD::__copy_constexpr( + __unwrap_iter(__first), __unwrap_iter(__last), __unwrap_iter(__result)); + } else { + return _VSTD::__copy( + __unwrap_iter(__first), __unwrap_iter(__last), __unwrap_iter(__result)); + } } // copy_backward template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator -__copy_backward(_BidirectionalIterator __first, _BidirectionalIterator __last, _OutputIterator __result) +__copy_backward_constexpr(_BidirectionalIterator __first, _BidirectionalIterator __last, _OutputIterator __result) { while (__first != __last) *--__result = *--__last; return __result; } +template +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +__copy_backward(_BidirectionalIterator __first, _BidirectionalIterator __last, _OutputIterator __result) +{ + return __copy_backward_constexpr(__first, __last, __result); +} + template inline _LIBCPP_INLINE_VISIBILITY typename enable_if @@ -1758,20 +1780,26 @@ __copy_backward(_Tp* __first, _Tp* __last, _Up* __result) } template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17_WITH_IS_CONSTANT_EVALUATED _BidirectionalIterator2 copy_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last, _BidirectionalIterator2 __result) { - return _VSTD::__copy_backward(__unwrap_iter(__first), - __unwrap_iter(__last), - __unwrap_iter(__result)); + if (__libcpp_is_constant_evaluated()) { + return _VSTD::__copy_backward_constexpr(__unwrap_iter(__first), + __unwrap_iter(__last), + __unwrap_iter(__result)); + } else { + return _VSTD::__copy_backward(__unwrap_iter(__first), + __unwrap_iter(__last), + __unwrap_iter(__result)); + } } // copy_if template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Predicate __pred) @@ -1790,11 +1818,11 @@ copy_if(_InputIterator __first, _InputIterator __last, // copy_n template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17_WITH_IS_CONSTANT_EVALUATED typename enable_if < - __is_input_iterator<_InputIterator>::value && - !__is_random_access_iterator<_InputIterator>::value, + __is_cpp17_input_iterator<_InputIterator>::value && + !__is_cpp17_random_access_iterator<_InputIterator>::value, _OutputIterator >::type copy_n(_InputIterator __first, _Size __orig_n, _OutputIterator __result) @@ -1816,10 +1844,10 @@ copy_n(_InputIterator __first, _Size __orig_n, _OutputIterator __result) } template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17_WITH_IS_CONSTANT_EVALUATED typename enable_if < - __is_random_access_iterator<_InputIterator>::value, + __is_cpp17_random_access_iterator<_InputIterator>::value, _OutputIterator >::type copy_n(_InputIterator __first, _Size __orig_n, _OutputIterator __result) @@ -2492,7 +2520,7 @@ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) { - static_assert(__is_forward_iterator<_ForwardIterator>::value, + static_assert(__is_cpp17_forward_iterator<_ForwardIterator>::value, "std::min_element requires a ForwardIterator"); if (__first != __last) { @@ -2564,7 +2592,7 @@ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) { - static_assert(__is_forward_iterator<_ForwardIterator>::value, + static_assert(__is_cpp17_forward_iterator<_ForwardIterator>::value, "std::max_element requires a ForwardIterator"); if (__first != __last) { @@ -2659,7 +2687,7 @@ _LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX11 std::pair<_ForwardIterator, _ForwardIterator> minmax_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) { - static_assert(__is_forward_iterator<_ForwardIterator>::value, + static_assert(__is_cpp17_forward_iterator<_ForwardIterator>::value, "std::minmax_element requires a ForwardIterator"); std::pair<_ForwardIterator, _ForwardIterator> __result(__first, __first); if (__first != __last) @@ -3117,10 +3145,10 @@ _SampleIterator __sample(_PopulationIterator __first, input_iterator_tag) { _Distance __k = 0; - for (; __first != __last && __k < __n; ++__first, (void)++__k) + for (; __first != __last && __k < __n; ++__first, (void) ++__k) __output_iter[__k] = *__first; _Distance __sz = __k; - for (; __first != __last; ++__first, (void)++__k) { + for (; __first != __last; ++__first, (void) ++__k) { _Distance __r = _VSTD::uniform_int_distribution<_Distance>(0, __k)(__g); if (__r < __sz) __output_iter[__r] = *__first; @@ -3158,8 +3186,8 @@ _SampleIterator __sample(_PopulationIterator __first, _PopCategory; typedef typename iterator_traits<_PopulationIterator>::difference_type _Difference; - static_assert(__is_forward_iterator<_PopulationIterator>::value || - __is_random_access_iterator<_SampleIterator>::value, + static_assert(__is_cpp17_forward_iterator<_PopulationIterator>::value || + __is_cpp17_random_access_iterator<_SampleIterator>::value, "SampleIterator must meet the requirements of RandomAccessIterator"); typedef typename common_type<_Distance, _Difference>::type _CommonType; _LIBCPP_ASSERT(__n >= 0, "N must be a positive number."); @@ -3190,7 +3218,7 @@ template if (__d > 1) { _Dp __uid; - for (--__last, --__d; __first < __last; ++__first, --__d) + for (--__last, (void) --__d; __first < __last; ++__first, (void) --__d) { difference_type __i = __uid(__g, _Pp(0, __d)); if (__i != difference_type(0)) @@ -3373,7 +3401,7 @@ __stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate // All trues now at start of range, all falses in buffer // Move falses back into range, but don't mess up __first which points to first false __i = __first; - for (value_type* __t2 = __p.first; __t2 < __t; ++__t2, ++__i) + for (value_type* __t2 = __p.first; __t2 < __t; ++__t2, (void) ++__i) *__i = _VSTD::move(*__t2); // __h destructs moved-from values out of the temp buffer, but doesn't deallocate buffer return __first; @@ -3505,7 +3533,7 @@ __stable_partition(_BidirectionalIterator __first, _BidirectionalIterator __last __i = ++__first; // All trues now at start of range, all falses in buffer // Move falses back into range, but don't mess up __first which points to first false - for (value_type* __t2 = __p.first; __t2 < __t; ++__t2, ++__i) + for (value_type* __t2 = __p.first; __t2 < __t; ++__t2, (void) ++__i) *__i = _VSTD::move(*__t2); // __h destructs moved-from values out of the temp buffer, but doesn't deallocate buffer return __first; @@ -4382,7 +4410,7 @@ merge(_InputIterator1 __first1, _InputIterator1 __last1, { typedef typename iterator_traits<_InputIterator1>::value_type __v1; typedef typename iterator_traits<_InputIterator2>::value_type __v2; - return merge(__first1, __last1, __first2, __last2, __result, __less<__v1, __v2>()); + return _VSTD::merge(__first1, __last1, __first2, __last2, __result, __less<__v1, __v2>()); } // inplace_merge @@ -4428,14 +4456,14 @@ __buffered_inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator if (__len1 <= __len2) { value_type* __p = __buff; - for (_BidirectionalIterator __i = __first; __i != __middle; __d.__incr((value_type*)0), (void) ++__i, ++__p) + for (_BidirectionalIterator __i = __first; __i != __middle; __d.__incr((value_type*)0), (void) ++__i, (void) ++__p) ::new(__p) value_type(_VSTD::move(*__i)); __half_inplace_merge(__buff, __p, __middle, __last, __first, __comp); } else { value_type* __p = __buff; - for (_BidirectionalIterator __i = __middle; __i != __last; __d.__incr((value_type*)0), (void) ++__i, ++__p) + for (_BidirectionalIterator __i = __middle; __i != __last; __d.__incr((value_type*)0), (void) ++__i, (void) ++__p) ::new(__p) value_type(_VSTD::move(*__i)); typedef reverse_iterator<_BidirectionalIterator> _RBi; typedef reverse_iterator _Rv; @@ -4575,14 +4603,14 @@ __merge_move_construct(_InputIterator1 __first1, _InputIterator1 __last1, { if (__first1 == __last1) { - for (; __first2 != __last2; ++__first2, ++__result, __d.__incr((value_type*)0)) + for (; __first2 != __last2; ++__first2, ++__result, (void) __d.__incr((value_type*)0)) ::new (__result) value_type(_VSTD::move(*__first2)); __h.release(); return; } if (__first2 == __last2) { - for (; __first1 != __last1; ++__first1, ++__result, __d.__incr((value_type*)0)) + for (; __first1 != __last1; ++__first1, ++__result, (void) __d.__incr((value_type*)0)) ::new (__result) value_type(_VSTD::move(*__first1)); __h.release(); return; @@ -4612,7 +4640,7 @@ __merge_move_assign(_InputIterator1 __first1, _InputIterator1 __last1, { if (__first2 == __last2) { - for (; __first1 != __last1; ++__first1, ++__result) + for (; __first1 != __last1; ++__first1, (void) ++__result) *__result = _VSTD::move(*__first1); return; } @@ -4627,7 +4655,7 @@ __merge_move_assign(_InputIterator1 __first1, _InputIterator1 __last1, ++__first1; } } - for (; __first2 != __last2; ++__first2, ++__result) + for (; __first2 != __last2; ++__first2, (void) ++__result) *__result = _VSTD::move(*__first2); } @@ -4995,7 +5023,7 @@ void __sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; - for (difference_type __n = __last - __first; __n > 1; --__last, --__n) + for (difference_type __n = __last - __first; __n > 1; --__last, (void) --__n) __pop_heap<_Compare>(__first, __last, __comp, __n); } @@ -5065,7 +5093,7 @@ __partial_sort_copy(_InputIterator __first, _InputIterator __last, _RandomAccessIterator __r = __result_first; if (__r != __result_last) { - for (; __first != __last && __r != __result_last; (void) ++__first, ++__r) + for (; __first != __last && __r != __result_last; ++__first, (void) ++__r) *__r = *__first; __make_heap<_Compare>(__result_first, __r, __comp); typename iterator_traits<_RandomAccessIterator>::difference_type __len = __r - __result_first; @@ -5678,4 +5706,8 @@ _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS +#if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17 +# include <__pstl_algorithm> +#endif + #endif // _LIBCPP_ALGORITHM -- cgit v1.2.3