<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 823: identity&lt;void&gt; seems broken</title>
<meta property="og:title" content="Issue 823: identity&lt;void&gt; seems broken">
<meta property="og:description" content="C++ library issue. Status: Resolved">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue823.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#Resolved">Resolved</a> status.</em></p>
<h3 id="823"><a href="lwg-defects.html#823">823</a>. <code>identity&lt;void&gt;</code> seems broken</h3>
<p><b>Section:</b> 22.2.4 <a href="https://wg21.link/forward">[forward]</a> <b>Status:</b> <a href="lwg-active.html#Resolved">Resolved</a>
 <b>Submitter:</b> Walter Brown <b>Opened:</b> 2008-04-09 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all other</b> <a href="lwg-index.html#forward">issues</a> in [forward].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#Resolved">Resolved</a> status.</p>
<p><b>Discussion:</b></p>
<p>
N2588 seems to have added an <code>operator()</code> member function to the
<code>identity&lt;&gt;</code> helper in 22.2.4 <a href="https://wg21.link/forward">[forward]</a>.  I believe this change makes it no
longer possible to instantiate <code>identity&lt;void&gt;</code>, as it would require
forming a reference-to-<code>void</code> type as this <code>operator()</code>'s parameter type.
</p>

<p>
Suggested resolution:  Specialize <code>identity&lt;void&gt;</code> so as not to require
the member function's presence.
</p>

<p><i>[
Sophia Antipolis:
]</i></p>


<blockquote>
<p>
Jens: suggests to add a requires clause to avoid specializing on <code>void</code>.
</p>
<p>
Alisdair: also consider cv-qualified <code>void</code>.
</p>
<p>
Alberto provided proposed wording.
</p>
</blockquote>

<p><i>[
2009-07-30 Daniel reopens:
]</i></p>


<blockquote>
<p>
This issue became closed, because the <code>ReferentType</code> requirement
fixed the problem - this is no longer the case. In retrospective it seems
to be that the root of current issues around <code>std::identity</code> (823, <a href="lwg-defects.html#700" title="N1856 defines struct identity (Status: CD1)">700</a><sup><a href="https://cplusplus.github.io/LWG/issue700" title="Latest snapshot">(i)</a></sup>,
<a href="lwg-defects.html#939" title="Problem with std::identity and reference-to-temporaries (Status: C++11)">939</a><sup><a href="https://cplusplus.github.io/LWG/issue939" title="Latest snapshot">(i)</a></sup>)
is that it was standardized as something very different (an unconditional
type mapper) than traditional usage indicated (a function object that should
derive from <code>std::unary_function)</code>, as the SGI definition does. This issue could
be solved, if <code>std::identity</code> is removed (one proposal of <a href="lwg-defects.html#939" title="Problem with std::identity and reference-to-temporaries (Status: C++11)">939</a><sup><a href="https://cplusplus.github.io/LWG/issue939" title="Latest snapshot">(i)</a></sup>), but until this
has been decided, this issue should remain open. An alternative for
removing it, would be, to do the following:
</p>

<ol style="list-style-type:lower-alpha">
<li>
<p>
Let <code>identity</code> stay as a <em>real</em> function object, which would
now properly
derive from <code>unary_function</code>:
</p>

<blockquote><pre>
template &lt;class T&gt; struct identity : unary_function&lt;T, T&gt; {
  const T&amp; operator()(const T&amp;) const;
};
</pre></blockquote>
</li>

<li>
<p>
Invent (if needed) a generic type wrapper (corresponding to concept
<code>IdentityOf</code>),
e.g. <code>identity_of</code>, and move it's prototype description back to 22.2.4 <a href="https://wg21.link/forward">[forward]</a>:
</p>

<blockquote><pre>
template &lt;class T&gt; struct identity_of {
  typedef T type;
};
</pre></blockquote>

<p>
and adapt the <code>std::forward</code> signature to use <code>identity_of</code>
instead of <code>identity</code>.
</p>
</li>
</ol>
</blockquote>

<p><i>[
2009-10 Santa Cruz:
]</i></p>


<blockquote><p>
Mark as <del>NAD Editorial</del><ins>Resolved</ins>, fixed by <a href="lwg-defects.html#939" title="Problem with std::identity and reference-to-temporaries (Status: C++11)">939</a><sup><a href="https://cplusplus.github.io/LWG/issue939" title="Latest snapshot">(i)</a></sup>.
</p></blockquote>



<p id="res-823"><b>Proposed resolution:</b></p>
<p>
Change definition of <code>identity</code> in 22.2.4 <a href="https://wg21.link/forward">[forward]</a>, paragraph 2, to:
</p>

<blockquote><pre>
template &lt;class T&gt;  struct identity {
    typedef T type;

    <ins>requires ReferentType&lt;T&gt;</ins>
      const T&amp; operator()(const T&amp; x) const;
  };
</pre></blockquote>
<p>...</p>
<blockquote><pre>
  <ins>requires ReferentType&lt;T&gt;</ins>
    const T&amp; operator()(const T&amp; x) const;
</pre></blockquote>


<p><b>Rationale:</b></p>
<p>
The point here is to able to write <code>T&amp;</code> given <code>T</code> and <code>ReferentType</code> is
precisely the concept that guarantees so, according to N2677
(Foundational concepts). Because of this, it seems preferable than an
explicit check for <code>cv void</code> using <code>SameType/remove_cv</code> as it was suggested
in Sophia. In particular, Daniel remarked that there may be types other
than <code>cv void</code> which aren't referent types (<code>int[]</code>, perhaps?).
</p>





</body>
</html>
