C++ Logo


Advanced search

std::ranges::for_each with execution policy

From: JIMMY HU <s103360021_at_[hidden]>
Date: Tue, 23 Nov 2021 12:13:36 +0800

I've checked the document of std::for_each (
https://en.cppreference.com/w/cpp/algorithm/for_each) and
std::ranges::for_each (
https://en.cppreference.com/w/cpp/algorithm/ranges/for_each). I think that
execution policy can be added into std::ranges::for_each function and the
following overloading structure can be considered.

template< class ExecutionPolicy, std::input_iterator I,
std::sentinel_for<I> S, class Proj = std::identity,
std::indirectly_unary_invocable<std::projected<I, Proj>> Fun >requires
constexpr for_each_result<I, Fun>
          for_each( ExecutionPolicy&& policy, I first, S last, Fun f,
Proj proj = {} );
template< class ExecutionPolicy, ranges::input_range R, class Proj =
Proj>> Fun >requires
constexpr for_each_result<ranges::borrowed_iterator_t<R>, Fun>
          for_each( ExecutionPolicy&& policy, R&& r, Fun f, Proj proj = {} );

An advantage of this design is to integrate parallel algorithm into
ranges::for_each function.

I am trying to make some possible implementations and I want to hear some
feedback about this idea. The formal description for Std-Proposals of this
feature is working on Thank you so much.

Jimmy Hu

Nov. 23, 2021

Received on 2021-11-22 22:13:53