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

### 2039. Issues with `std::reverse` and `std::copy_if`

Section: 25.7.1 [alg.copy], 25.7.10 [alg.reverse] Status: C++14 Submitter: Nikolay Ivchenkov Opened: 2011-03-02 Last modified: 2016-01-28

Priority: Not Prioritized

View other active issues in [alg.copy].

View all other issues in [alg.copy].

View all issues with C++14 status.

Discussion:

1. In the description of `std::reverse`

   > Effects: For each non-negative integer `i <= (last - first)/2`, applies `iter_swap` to all pairs of iterators `first + i`, `(last - i) - 1`.

   should be changed to

   > Effects: For each non-negative integer `i < (last - first)/2`, applies `iter_swap` to all pairs of iterators `first + i`, `(last - i) - 1`.

   Here `i` shall be strictly less than `(last - first)/2`.

2. In the description of `std::copy_if` Returns paragraph is missing.

[2011-03-02: Daniel drafts wording]

Proposed resolution:

1. Modify 25.7.10 [alg.reverse] p. 1 as indicated:

   > 1 Effects: For each non-negative integer `i <= (last - first)/2`, applies `iter_swap` to all pairs of iterators `first + i`, `(last - i) - 1`.

2. Add the following Returns element after 25.7.1 [alg.copy] p. 9:

   >     template<class InputIterator, class OutputIterator, class Predicate>
   >     OutputIterator copy_if(InputIterator first, InputIterator last,
   >        OutputIterator result, Predicate pred);

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

   > > 9 Effects: Copies all of the elements referred to by the iterator `i` in the range `[first,last)` for which `pred(*i)` is true.

   > > ?? Returns: The end of the resulting range.

   > > 10 Complexity: Exactly `last - first` applications of the corresponding predicate.

   > > 11 Remarks: Stable.