diff options
author | Maxim Yurchuk <maxim-yurchuk@ydb.tech> | 2024-11-20 17:37:57 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-20 17:37:57 +0000 |
commit | f76323e9b295c15751e51e3443aa47a36bee8023 (patch) | |
tree | 4113c8cad473a33e0f746966e0cf087252fa1d7a /contrib/libs/cxxsupp/libcxx/include/__numeric/pstl_reduce.h | |
parent | 753ecb8d410a4cb459c26f3a0082fb2d1724fe63 (diff) | |
parent | a7b9a6afea2a9d7a7bfac4c5eb4c1a8e60adb9e6 (diff) | |
download | ydb-f76323e9b295c15751e51e3443aa47a36bee8023.tar.gz |
Merge pull request #11788 from ydb-platform/mergelibs-241120-1113
Library import 241120-1113
Diffstat (limited to 'contrib/libs/cxxsupp/libcxx/include/__numeric/pstl_reduce.h')
-rw-r--r-- | contrib/libs/cxxsupp/libcxx/include/__numeric/pstl_reduce.h | 51 |
1 files changed, 41 insertions, 10 deletions
diff --git a/contrib/libs/cxxsupp/libcxx/include/__numeric/pstl_reduce.h b/contrib/libs/cxxsupp/libcxx/include/__numeric/pstl_reduce.h index 22ef2707d7..b19972a46d 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__numeric/pstl_reduce.h +++ b/contrib/libs/cxxsupp/libcxx/include/__numeric/pstl_reduce.h @@ -33,16 +33,16 @@ template <class _ExecutionPolicy, class _BinaryOperation = plus<>, class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>, enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0> -_LIBCPP_HIDE_FROM_ABI _Tp -reduce(_ExecutionPolicy&& __policy, - _ForwardIterator __first, - _ForwardIterator __last, - _Tp __init, - _BinaryOperation __op = {}) { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<_Tp> +__reduce(_ExecutionPolicy&& __policy, + _ForwardIterator&& __first, + _ForwardIterator&& __last, + _Tp&& __init, + _BinaryOperation&& __op = {}) noexcept { return std::__pstl_frontend_dispatch( _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_reduce, _RawPolicy), [&__policy](_ForwardIterator __g_first, _ForwardIterator __g_last, _Tp __g_init, _BinaryOperation __g_op) { - return std::transform_reduce( + return std::__transform_reduce( __policy, std::move(__g_first), std::move(__g_last), std::move(__g_init), std::move(__g_op), __identity{}); }, std::move(__first), @@ -53,19 +53,50 @@ reduce(_ExecutionPolicy&& __policy, template <class _ExecutionPolicy, class _ForwardIterator, + class _Tp, + class _BinaryOperation = plus<>, class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>, enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0> -_LIBCPP_HIDE_FROM_ABI __iter_value_type<_ForwardIterator> -reduce(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last) { +_LIBCPP_HIDE_FROM_ABI _Tp +reduce(_ExecutionPolicy&& __policy, + _ForwardIterator __first, + _ForwardIterator __last, + _Tp __init, + _BinaryOperation __op = {}) { + auto __res = std::__reduce(__policy, std::move(__first), std::move(__last), std::move(__init), std::move(__op)); + if (!__res) + std::__throw_bad_alloc(); + return *std::move(__res); +} + +template <class _ExecutionPolicy, + class _ForwardIterator, + class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>, + enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0> +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<__iter_value_type<_ForwardIterator>> +__reduce(_ExecutionPolicy&& __policy, _ForwardIterator&& __first, _ForwardIterator&& __last) noexcept { return std::__pstl_frontend_dispatch( _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_reduce, _RawPolicy), [&__policy](_ForwardIterator __g_first, _ForwardIterator __g_last) { - return std::reduce(__policy, __g_first, __g_last, __iter_value_type<_ForwardIterator>()); + return std::__reduce( + __policy, std::move(__g_first), std::move(__g_last), __iter_value_type<_ForwardIterator>()); }, std::move(__first), std::move(__last)); } +template <class _ExecutionPolicy, + class _ForwardIterator, + class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>, + enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0> +_LIBCPP_HIDE_FROM_ABI __iter_value_type<_ForwardIterator> +reduce(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last) { + auto __res = std::__reduce(__policy, std::move(__first), std::move(__last)); + if (!__res) + std::__throw_bad_alloc(); + return *std::move(__res); +} + _LIBCPP_END_NAMESPACE_STD #endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17 |