<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2768: any_cast and move semantics</title>
<meta property="og:title" content="Issue 2768: any_cast and move semantics">
<meta property="og:description" content="C++ library issue. Status: C++17">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2768.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="2768"><a href="lwg-defects.html#2768">2768</a>. <code>any_cast</code> and move semantics</h3>
<p><b>Section:</b> 22.7.5 <a href="https://wg21.link/any.nonmembers">[any.nonmembers]</a> <b>Status:</b> <a href="lwg-active.html#C++17">C++17</a>
 <b>Submitter:</b> Casey Carter <b>Opened:</b> 2016-08-27 <b>Last modified:</b> 2017-07-30</p>
<p><b>Priority: </b>0
</p>
<p><b>View all other</b> <a href="lwg-index.html#any.nonmembers">issues</a> in [any.nonmembers].</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>
LWG <a href="lwg-defects.html#2509" title="[fund.ts.v2] any_cast doesn't work with rvalue reference targets and cannot move with a value target (Status: TS)">2509</a><sup><a href="https://cplusplus.github.io/LWG/issue2509" title="Latest snapshot">(i)</a></sup> made two changes to the specification of <code>any</code> in v2 of the library fundamentals TS:
</p>

<ol>
<li>It altered the effects of the <code>any_cast(any&amp;&amp;)</code> overload to enable moving the value out of the <code>any</code> 
object and/or obtaining an rvalue reference to the contained value.</li>

<li>It made changes to support pathological copyable-but-not-movable contained values, which is madness.</li>
</ol>

<p>
Change 1 has very desirable effects; I propose that we apply the sane part of LWG <a href="lwg-defects.html#2509" title="[fund.ts.v2] any_cast doesn't work with rvalue reference targets and cannot move with a value target (Status: TS)">2509</a><sup><a href="https://cplusplus.github.io/LWG/issue2509" title="Latest snapshot">(i)</a></sup> to <code>any</code> 
in the C++17 WP, for all of the reasons cited in the discussion of LWG <a href="lwg-defects.html#2509" title="[fund.ts.v2] any_cast doesn't work with rvalue reference targets and cannot move with a value target (Status: TS)">2509</a><sup><a href="https://cplusplus.github.io/LWG/issue2509" title="Latest snapshot">(i)</a></sup>.
</p>

<p><i>[2016-09-09 Issues Resolution Telecon]</i></p>

<p>P0; move to Tentatively Ready</p>

<p><strong>Previous resolution [SUPERSEDED]:</strong></p>
<blockquote class="note">
<p>
This wording is relative to N4606.
</p>

<ol>
<li><p>In 22.7.5 <a href="https://wg21.link/any.nonmembers">[any.nonmembers]</a> p5, edit as follows:</p>
<blockquote>
<pre>
template&lt;class ValueType&gt;
  ValueType any_cast(const any&amp; operand);
template&lt;class ValueType&gt;
  ValueType any_cast(any&amp; operand);
template&lt;class ValueType&gt;
  ValueType any_cast(any&amp;&amp; operand);
</pre>
<blockquote>
<p>
-4- <i>Requires</i>: <code>is_reference_v&lt;ValueType&gt;</code> is <code>true</code> or <code>is_copy_constructible_v&lt;ValueType&gt;</code> 
is <code>true</code>. Otherwise the program is ill-formed. 
</p>
<p>
-5- <i>Returns</i>: For the first form, <code>*any_cast&lt;add_const_t&lt;remove_reference_t&lt;ValueType&gt;&gt;&gt;(&amp;operand)</code>. 
For the second <del>and third</del> form<del>s</del>, <code>*any_cast&lt;remove_reference_t&lt;ValueType&gt;&gt;(&amp;operand)</code>. 
<ins>For the third form, <code>std::forward&lt;ValueType&gt;(*any_cast&lt;remove_reference_t&lt;ValueType&gt;&gt;(&amp;operand))</code>.</ins>
</p>
<p>
[&hellip;]
</p>
</blockquote>
</blockquote>
</li>
</ol>

</blockquote>
<p><i>[Issues Telecon 16-Dec-2016]</i></p>

<p>Move to Tentatively Ready</p>


<p id="res-2768"><b>Proposed resolution:</b></p>
<p>
Resolved by the wording provided by LWG <a href="lwg-defects.html#2769" title="Redundant const in the return type of any_cast(const any&amp;) (Status: C++17)">2769</a><sup><a href="https://cplusplus.github.io/LWG/issue2769" title="Latest snapshot">(i)</a></sup>.
</p>






</body>
</html>
