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.

2747. Possibly redundant std::move in [alg.foreach]

Section: 23.5.4 [alg.foreach] Status: C++17 Submitter: Jonathan Wakely Opened: 2016-07-15 Last modified: 2017-07-30

Priority: 0

View all other issues in [alg.foreach].

View all issues with C++17 status.


23.5.4 [alg.foreach] p3 says Returns: std::move(f).

[class.copy] says that since f is a function parameter overload resolution to select the constructor for the return value is first performed as if for an rvalue, so the std::move is redundant.

It could be argued that it isn't entirely redundant, because it says that implementations can't do something slightly different like return an lvalue reference that is bound to f, which would prevent it being treated as an rvalue. We should discuss it.

[2016-07 Chicago]

Monday: P0 - tentatively ready

Proposed resolution:

This wording is relative to N4606.

  1. Change 23.5.4 [alg.foreach] as indicated:

    template<class InputIterator, class Function>
      Function for_each(InputIterator first, InputIterator last, Function f);


    -3- Returns: std::move(f).