<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2486: mem_fn() should be required to use perfect forwarding</title>
<meta property="og:title" content="Issue 2486: mem_fn() should be required to use perfect forwarding">
<meta property="og:description" content="C++ library issue. Status: C++17">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2486.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#C++17">C++17</a> status.</em></p>
<h3 id="2486"><a href="lwg-defects.html#2486">2486</a>. <code>mem_fn()</code> should be required to use perfect forwarding</h3>
<p><b>Section:</b> 22.10.4 <a href="https://wg21.link/func.require">[func.require]</a> <b>Status:</b> <a href="lwg-active.html#C++17">C++17</a>
 <b>Submitter:</b> Stephan T. Lavavej <b>Opened:</b> 2015-03-27 <b>Last modified:</b> 2017-07-30</p>
<p><b>Priority: </b>0
</p>
<p><b>View other</b> <a href="lwg-index-open.html#func.require">active issues</a> in [func.require].</p>
<p><b>View all other</b> <a href="lwg-index.html#func.require">issues</a> in [func.require].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++17">C++17</a> status.</p>
<p><b>Discussion:</b></p>
<p>
22.10.4 <a href="https://wg21.link/func.require">[func.require]</a>/4 defines "simple call wrapper" and "forwarding call wrapper". Only <code>mem_fn()</code> is 
specified to be a "simple call wrapper", by 22.10.16 <a href="https://wg21.link/func.memfn">[func.memfn]</a>/1: "A simple call wrapper (20.9.1) <code>fn</code> 
such that the expression <code>fn(t, a2, ..., aN)</code> is equivalent to <code>INVOKE(pm, t, a2, ..., aN)</code> (20.9.2)."
<p/>
This suggests, but doesn't outright state, that perfect forwarding is involved. It matters for PMFs like 
<code>R (T::*)(Arg)</code> where <code>Arg</code> is passed by value &mdash; if the <code>mem_fn()</code> wrapper's function call 
operator takes <code>Arg</code> by value, an extra copy/move will be observable. We should require perfect forwarding here.
</p>

<p><i>[2015-05, Lenexa]</i></p>

<p>
Move to Immediate.
</p>



<p id="res-2486"><b>Proposed resolution:</b></p>
<p>This wording is relative to N4296.</p>

<ol>
<li><p>Change 22.10.4 <a href="https://wg21.link/func.require">[func.require]</a> as depicted [<i>Editorial remark</i>: This simply adds "A simple call wrapper 
is a <ins>forwarding</ins> call wrapper", then moves the sentence. &mdash; <i>end of remark</i>]:</p>

<blockquote>
<p>
-4- Every call wrapper (20.9.1) shall be <code>MoveConstructible</code>. <del>A <i>simple call wrapper</i> is a call wrapper that is
<code>CopyConstructible</code> and <code>CopyAssignable</code> and whose copy constructor, move constructor, and assignment
operator do not throw exceptions.</del> A <i>forwarding call wrapper</i> 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. <ins>A <i>simple call wrapper</i> is a forwarding call wrapper that is <code>CopyConstructible</code> 
and <code>CopyAssignable</code> and whose copy constructor, move constructor, and assignment operator do not throw exceptions.</ins> 
[<i>Note</i>: In a typical implementation [&hellip;] &mdash; <i>end note</i>]
</p>
</blockquote>
</li>

</ol>






</body>
</html>
