This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++17 status.

2689. Parallel versions of std::copy and std::move shouldn't be in order

Section: 27.7.1 [alg.copy], 27.7.2 [alg.move] Status: C++17 Submitter: Tim Song Opened: 2016-03-23 Last modified: 2017-07-30

Priority: 0

View other active issues in [alg.copy].

View all other issues in [alg.copy].

View all issues with C++17 status.

Discussion:

27.3.5 [algorithms.parallel.overloads]/2 says that "Unless otherwise specified, the semantics of ExecutionPolicy algorithm overloads are identical to their overloads without."

There's no "otherwise specified" for the ExecutionPolicy overloads for std::copy and std::move, so the requirement that they "start[] from first and proceed[] to last" in the original algorithm's description would seem to apply, which defeats the whole point of adding a parallel overload.

[2016-05 Issues Telecon]

Marshall noted that all three versions of copy have subtly different wording, and suggested that they should not.

Proposed resolution:

This wording is relative to N4582.

  1. Insert the following paragraphs after 27.7.1 [alg.copy]/4:

    template<class ExecutionPolicy, class InputIterator, class OutputIterator>
      OutputIterator copy(ExecutionPolicy&& policy, InputIterator first, InputIterator last,
                          OutputIterator result);
    

    -?- Requires: The ranges [first, last) and [result, result + (last - first)) shall not overlap.

    -?- Effects: Copies elements in the range [first, last) into the range [result, result + (last - first)). For each non-negative integer n < (last - first), performs *(result + n) = *(first + n).

    -?- Returns: result + (last - first).

    -?- Complexity: Exactly last - first assignments.

  2. Insert the following paragraphs after 27.7.2 [alg.move]/4:

    template<class ExecutionPolicy, class InputIterator, class OutputIterator>
      OutputIterator move(ExecutionPolicy&& policy, InputIterator first, InputIterator last,
                          OutputIterator result);
    

    -?- Requires: The ranges [first, last) and [result, result + (last - first)) shall not overlap.

    -?- Effects: Moves elements in the range [first, last) into the range [result, result + (last - first)). For each non-negative integer n < (last - first), performs *(result + n) = std::move(*(first + n)).

    -?- Returns: result + (last - first).

    -?- Complexity: Exactly last - first assignments.