1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef _LIBCPP___ALGORITHM_PSTL_TRANSFORM_H
10 #define _LIBCPP___ALGORITHM_PSTL_TRANSFORM_H
11 
12 #include <__algorithm/pstl_backend.h>
13 #include <__config>
14 #include <__iterator/cpp17_iterator_concepts.h>
15 #include <__iterator/iterator_traits.h>
16 #include <__type_traits/enable_if.h>
17 #include <__type_traits/is_execution_policy.h>
18 #include <__type_traits/remove_cvref.h>
19 #include <__utility/move.h>
20 #include <__utility/terminate_on_exception.h>
21 
22 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
23 #  pragma GCC system_header
24 #endif
25 
26 #if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
27 
28 _LIBCPP_BEGIN_NAMESPACE_STD
29 
30 template <class _ExecutionPolicy,
31           class _ForwardIterator,
32           class _ForwardOutIterator,
33           class _UnaryOperation,
34           class _RawPolicy                                    = __remove_cvref_t<_ExecutionPolicy>,
35           enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
36 _LIBCPP_HIDE_FROM_ABI _ForwardOutIterator transform(
37     _ExecutionPolicy&&,
38     _ForwardIterator __first,
39     _ForwardIterator __last,
40     _ForwardOutIterator __result,
41     _UnaryOperation __op) {
42   _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator);
43   _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardOutIterator);
44   _LIBCPP_REQUIRE_CPP17_OUTPUT_ITERATOR(_ForwardOutIterator, decltype(__op(*__first)));
45   using _Backend = typename __select_backend<_RawPolicy>::type;
46   return std::__pstl_transform<_RawPolicy>(
47       _Backend{}, std::move(__first), std::move(__last), std::move(__result), std::move(__op));
48 }
49 
50 template <class _ExecutionPolicy,
51           class _ForwardIterator1,
52           class _ForwardIterator2,
53           class _ForwardOutIterator,
54           class _BinaryOperation,
55           class _RawPolicy                                    = __remove_cvref_t<_ExecutionPolicy>,
56           enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
57 _LIBCPP_HIDE_FROM_ABI _ForwardOutIterator transform(
58     _ExecutionPolicy&&,
59     _ForwardIterator1 __first1,
60     _ForwardIterator1 __last1,
61     _ForwardIterator2 __first2,
62     _ForwardOutIterator __result,
63     _BinaryOperation __op) {
64   _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator1);
65   _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator2);
66   _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardOutIterator);
67   _LIBCPP_REQUIRE_CPP17_OUTPUT_ITERATOR(_ForwardOutIterator, decltype(__op(*__first1, *__first2)));
68   using _Backend = typename __select_backend<_RawPolicy>::type;
69   return std::__pstl_transform<_RawPolicy>(
70       _Backend{}, std::move(__first1), std::move(__last1), std::move(__first2), std::move(__result), std::move(__op));
71 }
72 
73 _LIBCPP_END_NAMESPACE_STD
74 
75 #endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
76 
77 #endif // _LIBCPP___ALGORITHM_PSTL_TRANSFORM_H
78