Skip to content

[ranges] Considering adding ExecutionPolicy parameters into std::ranges::for_each #5132

Closed
@Jimmy-Hu

Description

@Jimmy-Hu

Hi,

I've checked there is a function overloading with ExecutionPolicy parameters in std::for_each:

template< class ExecutionPolicy, class ForwardIt, class UnaryFunction2 >
void for_each( ExecutionPolicy&& policy, ForwardIt first, ForwardIt last, UnaryFunction2 f );

I think that the execution policy parameters can also 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 (std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>)
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 =std::identity,
std::indirectly_unary_invocable<std::projected<ranges::iterator_t<R>,
Proj>> Fun >
requires (std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>)
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.

Activity

JohelEGP

JohelEGP commented on Dec 2, 2021

@JohelEGP
Contributor

The issue sounds like a proposal. Adding new overloads to ranges::for_each is not an editorial issue. I suggest you read the first section of the README for more information on what that might mean.

Jimmy-Hu

Jimmy-Hu commented on Dec 2, 2021

@Jimmy-Hu
Author

@JohelEGP Thank you for the prompt reply. I've checked the How to submit a new issue/defect report and an initial message to std-discussion have been posted. So the next step is to follow the instruction in "How to submit a core language or standard library issue" section? It's my first time to propose new proposal. Please let me know if there is any misunderstanding. Thank you so much.

JohelEGP

JohelEGP commented on Dec 2, 2021

@JohelEGP
Contributor

A linked webpage also has this: https://isocpp.org/std/submit-a-proposal.

jwakely

jwakely commented on Dec 2, 2021

@jwakely
Member

You need to submit a proposal. The issue process is for fixing defects. This is not a defect. The lack of parallel overloads for the ranges algo is intentional, not a mistake.

Closing as this is not editorial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @jwakely@Jimmy-Hu@JohelEGP

        Issue actions

          [ranges] Considering adding ExecutionPolicy parameters into std::ranges::for_each · Issue #5132 · cplusplus/draft