<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2487: bind() should be const-overloaded, not cv-overloaded</title>
<meta property="og:title" content="Issue 2487: bind() should be const-overloaded, not cv-overloaded">
<meta property="og:description" content="C++ library issue. Status: C++17">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2487.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="2487"><a href="lwg-defects.html#2487">2487</a>. <code>bind()</code> should be <code>const</code>-overloaded, not <i>cv</i>-overloaded</h3>
<p><b>Section:</b> 22.10.15.4 <a href="https://wg21.link/func.bind.bind">[func.bind.bind]</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>2
</p>
<p><b>View all other</b> <a href="lwg-index.html#func.bind.bind">issues</a> in [func.bind.bind].</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>
The Standard currently requires <code>bind()</code> to return something with a <i>cv</i>-overloaded function call operator.  
<code>const</code> is great, but <code>volatile</code> is not. First, the Library almost always ignores <code>volatile</code>'s 
existence (with <code>&lt;type_traits&gt;</code> and <code>&lt;atomic&gt;</code> being rare exceptions). Second, implementations 
typically store bound arguments in a <code>tuple</code>, but <code>get()</code> isn't overloaded for <code>volatile tuple</code>. Third, 
when a bound argument is a <code>reference_wrapper</code>, we have to call <code>tid.get()</code>, but that won't compile for a 
<code>volatile reference_wrapper</code>. Finally, <code>const</code> and <code>volatile</code> don't always have to be handled symmetrically 
&mdash; for example, lambda function call operators are <code>const</code> by default, but they can't ever be <code>volatile</code>.
<p/>
Implementers shouldn't be required to provide <i>cv</i>-overloading here. (They can provide it as a conforming extension if 
they want.)
</p>

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

<p>
JW: why would a <code>reference_wrapper</code> be volatile?<br/>
STL: if a bound argument is a <code>reference_wrapper</code> then in a volatile-qualified operator() that 
member will be volatile so you can't call get() on it<br/>
STL: worded like this it's a conforming extension to kep overloading on volatile<br/>
HH: libc++ doesn't overload on volatile<br/>
JW: libstdc++ does overload for volatile<br/>
MC: move to Ready and bring motion on Friday<br/>
10 in favor, none opposed 
</p>


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

<ol>
<li><p>Change 22.10.15.4 <a href="https://wg21.link/func.bind.bind">[func.bind.bind]</a> as depicted:</p>

<blockquote>
<pre>
template&lt;class F, class... BoundArgs&gt;
  <i>unspecified</i> bind(F&amp;&amp; f, BoundArgs&amp;&amp;... bound_args);
</pre>
<blockquote>
<p>
-2- <i>Requires</i>: <code>is_constructible&lt;FD, F&gt;::value</code> shall be <code>true</code>. For each <code>Ti</code> 
in <code>BoundArgs</code>, <code>is_constructible&lt;TiD, Ti&gt;::value</code> shall be <code>true</code>. 
<code><i>INVOKE</i>(fd, w1, w2, ..., wN)</code> (20.9.2) shall be a valid expression for some values <code>w1</code>, <code>w2</code>, 
..., <code>wN</code>, where <code>N == sizeof...(bound_args)</code>. <ins>The <i>cv</i>-qualifiers <i>cv</i> of the call 
wrapper <code>g</code>, as specified below, shall be neither <code>volatile</code> nor <code>const volatile</code>.</ins>
<p/>
[&hellip;]
</p>
</blockquote>
<pre>
template&lt;class R, class F, class... BoundArgs&gt;
  <i>unspecified</i> bind(F&amp;&amp; f, BoundArgs&amp;&amp;... bound_args);
</pre>
<blockquote>
<p>
-6- <i>Requires</i>: <code>is_constructible&lt;FD, F&gt;::value</code> shall be <code>true</code>. For each <code>Ti</code> 
in <code>BoundArgs</code>, <code>is_constructible&lt;TiD, Ti&gt;::value</code> shall be <code>true</code>. 
<code><i>INVOKE</i>(fd, w1, w2, ..., wN)</code> shall be a valid expression for some values <code>w1</code>, <code>w2</code>, 
..., <code>wN</code>, where <code>N == sizeof...(bound_args)</code>. <ins>The <i>cv</i>-qualifiers <i>cv</i> of the call 
wrapper <code>g</code>, as specified below, shall be neither <code>volatile</code> nor <code>const volatile</code>.</ins>
<p/>
[&hellip;]
</p>
</blockquote>
</blockquote>
</li>

</ol>






</body>
</html>
