@@ -53,6 +53,57 @@ namespace std {
5353 typename std::iterator_traits<RandIt>::value_type{});
5454 }
5555
56+ #if POOLSTL_HAVE_CXX17_LIB
57+ /**
58+ * NOTE: Iterators are expected to be random access.
59+ * See std::transform_reduce https://en.cppreference.com/w/cpp/algorithm/transform_reduce
60+ */
61+ template <class ExecPolicy, class RandIt1, class T, class BinaryReductionOp, class UnaryTransformOp>
62+ poolstl::internal::enable_if_poolstl_execution_policy<ExecPolicy, T>
63+ transform_reduce(ExecPolicy&& policy, RandIt1 first1, RandIt1 last1, T init,
64+ BinaryReductionOp reduce_op, UnaryTransformOp transform_op) {
65+
66+ auto futures = poolstl::internal::parallel_chunk_for(std::forward<ExecPolicy>(policy), first1, last1,
67+ [&init, &reduce_op, &transform_op](RandIt1 chunk_first1, RandIt1 chunk_last1) {
68+ return std::transform_reduce(chunk_first1, chunk_last1, init, reduce_op, transform_op);
69+ });
70+
71+ return poolstl::internal::cpp17::reduce(
72+ poolstl::internal::get_wrap(futures.begin()),
73+ poolstl::internal::get_wrap(futures.end()), init, reduce_op);
74+ }
75+
76+ /**
77+ * NOTE: Iterators are expected to be random access.
78+ * See std::transform_reduce https://en.cppreference.com/w/cpp/algorithm/transform_reduce
79+ */
80+ template <class ExecPolicy, class RandIt1, class RandIt2, class T, class BinaryReductionOp, class BinaryTransformOp>
81+ poolstl::internal::enable_if_poolstl_execution_policy<ExecPolicy, T>
82+ transform_reduce(ExecPolicy&& policy, RandIt1 first1, RandIt1 last1, RandIt2 first2, T init,
83+ BinaryReductionOp reduce_op, BinaryTransformOp transform_op) {
84+
85+ auto futures = poolstl::internal::parallel_chunk_for(std::forward<ExecPolicy>(policy), first1, last1, first2,
86+ [&init, &reduce_op, &transform_op](RandIt1 chunk_first1, RandIt1 chunk_last1, RandIt2 chunk_first2) {
87+ return std::transform_reduce(chunk_first1, chunk_last1, chunk_first2, init, reduce_op, transform_op);
88+ });
89+
90+ return poolstl::internal::cpp17::reduce(
91+ poolstl::internal::get_wrap(futures.begin()),
92+ poolstl::internal::get_wrap(futures.end()), init, reduce_op);
93+ }
94+
95+ /**
96+ * NOTE: Iterators are expected to be random access.
97+ * See std::transform_reduce https://en.cppreference.com/w/cpp/algorithm/transform_reduce
98+ */
99+ template< class ExecPolicy, class RandIt1, class RandIt2, class T >
100+ poolstl::internal::enable_if_poolstl_execution_policy<ExecPolicy, T>
101+ transform_reduce(ExecPolicy&& policy, RandIt1 first1, RandIt1 last1, RandIt2 first2, T init ) {
102+ return transform_reduce(std::forward<ExecPolicy>(policy),
103+ first1, last1, first2, init, std::plus<>(), std::multiplies<>());
104+ }
105+ #endif
106+
56107}
57108
58109#endif
0 commit comments