Path: blob/main/contrib/llvm-project/libcxx/include/__numeric/pstl.h
35233 views
//===----------------------------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef _LIBCPP___NUMERIC_PSTL_H9#define _LIBCPP___NUMERIC_PSTL_H1011#include <__config>1213#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)14# pragma GCC system_header15#endif1617_LIBCPP_PUSH_MACROS18#include <__undef_macros>1920#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 172122# include <__functional/identity.h>23# include <__functional/operations.h>24# include <__iterator/cpp17_iterator_concepts.h>25# include <__iterator/iterator_traits.h>26# include <__pstl/backend.h>27# include <__pstl/dispatch.h>28# include <__pstl/handle_exception.h>29# include <__type_traits/enable_if.h>30# include <__type_traits/is_execution_policy.h>31# include <__type_traits/remove_cvref.h>32# include <__utility/forward.h>33# include <__utility/move.h>3435_LIBCPP_BEGIN_NAMESPACE_STD3637template <class _ExecutionPolicy,38class _ForwardIterator,39class _Tp,40class _BinaryOperation,41class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,42enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>43_LIBCPP_HIDE_FROM_ABI _Tp reduce(44_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Tp __init, _BinaryOperation __op) {45_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "reduce requires ForwardIterators");46using _Implementation = __pstl::__dispatch<__pstl::__reduce, __pstl::__current_configuration, _RawPolicy>;47return __pstl::__handle_exception<_Implementation>(48std::forward<_ExecutionPolicy>(__policy),49std::move(__first),50std::move(__last),51std::move(__init),52std::move(__op));53}5455template <class _ExecutionPolicy,56class _ForwardIterator,57class _Tp,58class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,59enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>60_LIBCPP_HIDE_FROM_ABI _Tp61reduce(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Tp __init) {62_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "reduce requires ForwardIterators");63using _Implementation = __pstl::__dispatch<__pstl::__reduce, __pstl::__current_configuration, _RawPolicy>;64return __pstl::__handle_exception<_Implementation>(65std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), std::move(__init), plus{});66}6768template <class _ExecutionPolicy,69class _ForwardIterator,70class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,71enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>72_LIBCPP_HIDE_FROM_ABI __iter_value_type<_ForwardIterator>73reduce(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last) {74_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "reduce requires ForwardIterators");75using _Implementation = __pstl::__dispatch<__pstl::__reduce, __pstl::__current_configuration, _RawPolicy>;76return __pstl::__handle_exception<_Implementation>(77std::forward<_ExecutionPolicy>(__policy),78std::move(__first),79std::move(__last),80__iter_value_type<_ForwardIterator>(),81plus{});82}8384template <class _ExecutionPolicy,85class _ForwardIterator1,86class _ForwardIterator2,87class _Tp,88class _BinaryOperation1,89class _BinaryOperation2,90class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,91enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>92_LIBCPP_HIDE_FROM_ABI _Tp transform_reduce(93_ExecutionPolicy&& __policy,94_ForwardIterator1 __first1,95_ForwardIterator1 __last1,96_ForwardIterator2 __first2,97_Tp __init,98_BinaryOperation1 __reduce,99_BinaryOperation2 __transform) {100_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator1, "transform_reduce requires ForwardIterators");101_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator2, "transform_reduce requires ForwardIterators");102using _Implementation =103__pstl::__dispatch<__pstl::__transform_reduce_binary, __pstl::__current_configuration, _RawPolicy>;104return __pstl::__handle_exception<_Implementation>(105std::forward<_ExecutionPolicy>(__policy),106std::move(__first1),107std::move(__last1),108std::move(__first2),109std::move(__init),110std::move(__reduce),111std::move(__transform));112}113114// This overload doesn't get a customization point because it's trivial to detect (through e.g.115// __desugars_to_v) when specializing the more general variant, which should always be preferred116template <class _ExecutionPolicy,117class _ForwardIterator1,118class _ForwardIterator2,119class _Tp,120class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,121enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>122_LIBCPP_HIDE_FROM_ABI _Tp transform_reduce(123_ExecutionPolicy&& __policy,124_ForwardIterator1 __first1,125_ForwardIterator1 __last1,126_ForwardIterator2 __first2,127_Tp __init) {128_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator1, "transform_reduce requires ForwardIterators");129_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator2, "transform_reduce requires ForwardIterators");130using _Implementation =131__pstl::__dispatch<__pstl::__transform_reduce_binary, __pstl::__current_configuration, _RawPolicy>;132return __pstl::__handle_exception<_Implementation>(133std::forward<_ExecutionPolicy>(__policy),134std::move(__first1),135std::move(__last1),136std::move(__first2),137std::move(__init),138plus{},139multiplies{});140}141142template <class _ExecutionPolicy,143class _ForwardIterator,144class _Tp,145class _BinaryOperation,146class _UnaryOperation,147class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,148enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>149_LIBCPP_HIDE_FROM_ABI _Tp transform_reduce(150_ExecutionPolicy&& __policy,151_ForwardIterator __first,152_ForwardIterator __last,153_Tp __init,154_BinaryOperation __reduce,155_UnaryOperation __transform) {156_LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "transform_reduce requires ForwardIterators");157using _Implementation = __pstl::__dispatch<__pstl::__transform_reduce, __pstl::__current_configuration, _RawPolicy>;158return __pstl::__handle_exception<_Implementation>(159std::forward<_ExecutionPolicy>(__policy),160std::move(__first),161std::move(__last),162std::move(__init),163std::move(__reduce),164std::move(__transform));165}166167_LIBCPP_END_NAMESPACE_STD168169#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17170171_LIBCPP_POP_MACROS172173#endif // _LIBCPP___NUMERIC_PSTL_H174175176