Title
Possibly redundant std::move in [alg.foreach]
Status
c++17
Section
[alg.foreach]
Submitter
Jonathan Wakely

Created on 2016-07-15.00:00:00 last changed 81 months ago

Messages

Date: 2016-08-01.18:34:48

Proposed resolution:

This wording is relative to N4606.

  1. Change [alg.foreach] as indicated:

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

    […]

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

    […]

Date: 2016-08-01.18:34:48

[ 2016-07 Chicago ]

Monday: P0 - tentatively ready

Date: 2016-07-15.00:00:00

[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.

History
Date User Action Args
2017-07-30 20:15:43adminsetstatus: wp -> c++17
2016-11-14 03:59:28adminsetstatus: pending -> wp
2016-11-14 03:55:22adminsetstatus: ready -> pending
2016-08-01 18:34:48adminsetmessages: + msg8285
2016-08-01 18:34:48adminsetstatus: new -> ready
2016-07-24 20:11:53adminsetmessages: + msg8251
2016-07-15 00:00:00admincreate