2486. mem_fn() should be required to use perfect forwarding

Section: 23.14.3 [func.require] Status: C++17 Submitter: Stephan T. Lavavej Opened: 2015-03-27 Last modified: 2017-07-30

Priority: 0

View all other issues in [func.require].

View all issues with C++17 status.

Discussion:

23.14.3 [func.require]/4 defines "simple call wrapper" and "forwarding call wrapper". Only mem_fn() is specified to be a "simple call wrapper", by 23.14.12 [func.memfn]/1: "A simple call wrapper (20.9.1) fn such that the expression fn(t, a2, ..., aN) is equivalent to INVOKE(pm, t, a2, ..., aN) (20.9.2)."

This suggests, but doesn't outright state, that perfect forwarding is involved. It matters for PMFs like R (T::*)(Arg) where Arg is passed by value — if the mem_fn() wrapper's function call operator takes Arg by value, an extra copy/move will be observable. We should require perfect forwarding here.

[2015-05, Lenexa]

Move to Immediate.

Proposed resolution:

This wording is relative to N4296.

  1. Change 23.14.3 [func.require] as depicted [Editorial remark: This simply adds "A simple call wrapper is a forwarding call wrapper", then moves the sentence. — end of remark]:

    -4- Every call wrapper (20.9.1) shall be MoveConstructible. A simple call wrapper is a call wrapper that is CopyConstructible and CopyAssignable and whose copy constructor, move constructor, and assignment operator do not throw exceptions. A forwarding call wrapper is a call wrapper that can be called with an arbitrary argument list and delivers the arguments to the wrapped callable object as references. This forwarding step shall ensure that rvalue arguments are delivered as rvalue-references and lvalue arguments are delivered as lvalue-references. A simple call wrapper is a forwarding call wrapper that is CopyConstructible and CopyAssignable and whose copy constructor, move constructor, and assignment operator do not throw exceptions. [Note: In a typical implementation […] — end note]