<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2814: [fund.ts.v2] to_array should take rvalue reference as well</title>
<meta property="og:title" content="Issue 2814: [fund.ts.v2] to_array should take rvalue reference as well">
<meta property="og:description" content="C++ library issue. Status: Resolved">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2814.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="2814"><a href="lwg-defects.html#2814">2814</a>. [fund.ts.v2] <code>to_array</code> should take rvalue reference as well</h3>
<p><b>Section:</b> 4.2.1 <a href="https://cplusplus.github.io/fundamentals-ts/v2.html#func.wrap.func.con">[fund.ts.v2::func.wrap.func.con]</a> <b>Status:</b> <a href="lwg-active.html#Resolved">Resolved</a>
 <b>Submitter:</b> Zhihao Yuan <b>Opened:</b> 2016-11-07 <b>Last modified:</b> 2020-09-06</p>
<p><b>Priority: </b>3
</p>
<p><b>View all other</b> <a href="lwg-index.html#fund.ts.v2::func.wrap.func.con">issues</a> in [fund.ts.v2::func.wrap.func.con].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#Resolved">Resolved</a> status.</p>
<p><b>Discussion:</b></p>
<p><b>Addresses: fund.ts.v2</b></p>
<p>
C++ doesn't have a prvalue expression of array type, but
rvalue arrays can still come from different kinds of sources:
</p>
<ol>
<li><p>C99 compound literals <code>(int[]) {2, 4}</code>,</p></li>
<li><p><code>std::move(arr)</code>,</p></li>
<li><p>Deduction <code>to_array&lt;int const&gt;({ 2, 4 })</code>.</p>
<blockquote class="note">
<p>
See also <a href="https://wg21.link/cwg1591">CWG 1591</a>: Deducing array bound and element type from initializer list.
</p>
</blockquote>
</li>
</ol>
<p>
For 3), users are "abusing" <code>to_array</code> to get access to uniform
initialization to benefit from initializing elements through
braced-init-list and/or better narrowing conversion support.
<p/>
We should just add rvalue reference support to <code>to_array</code>.
</p>

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

<p>Status to LEWG</p>

<p><i>[2017-02 in Kona, LEWG responds]</i></p>

<p>Would like a small paper; see examples before and after. How does this affect overload resolution?</p>

<p><i>[2017-06-02 Issues Telecon]</i></p>

<p>Leave status as LEWG; priority 3</p>

<strong>Previous resolution [SUPERSEDED]:</strong>
<blockquote class="note">
<p>This wording is relative to <a href="https://wg21.link/n4600">N4600</a>.</p>

<ol>
<li>
<p>Add the following signature to 9.2.1 <a href="https://cplusplus.github.io/fundamentals-ts/v2.html#header.array.synop">[fund.ts.v2::header.array.synop]</a>:</p>

<blockquote>
<pre>
// 9.2.2, Array creation functions
template &lt;class D = void, class... Types&gt;
  constexpr array&lt;VT, sizeof...(Types)&gt; make_array(Types&amp;&amp;... t);
template &lt;class T, size_t N&gt;
  constexpr array&lt;remove_cv_t&lt;T&gt;, N&gt; to_array(T (&amp;a)[N]);
<ins>template &lt;class T, size_t N&gt;
  constexpr array&lt;remove_cv_t&lt;T&gt;, N&gt; to_array(T (&amp;&amp;a)[N]);</ins>
</pre>
</blockquote>
</li>

<li>
<p>Modify 9.2.2 <a href="https://cplusplus.github.io/fundamentals-ts/v2.html#container.array.creation">[fund.ts.v2::container.array.creation]</a> as follows:</p>

<blockquote>
<pre>
template &lt;class T, size_t N&gt;
  constexpr array&lt;remove_cv_t&lt;T&gt;, N&gt; to_array(T (&amp;a)[N]);
<ins>template &lt;class T, size_t N&gt;
  constexpr array&lt;remove_cv_t&lt;T&gt;, N&gt; to_array(T (&amp;&amp;a)[N]);</ins>
</pre>
<blockquote>
<p>
-6- <i>Returns:</i> <ins>For all <code><i>i</i></code>, <code>0 &le; <i>i</i> &lt; N</code>, a</ins><del>A</del>n 
<code>array&lt;remove_cv_t&lt;T&gt;, N&gt;</code> <del>such that each element is copy-initialized 
with the corresponding element of <code>a</code></del><ins>initialized with <code>{ a[<i>i</i>]... }</code> for 
the first form, or <code>{ std::move(a[<i>i</i>])... }</code> for the second form.</ins>.
</p>
</blockquote>
</blockquote>
</li>
</ol>
</blockquote>

<p><i>[2020-05-10; Reflector discussions]</i></p>

<p>
Resolved by adoption of <a href="https://wg21.link/p0325r4">P0325R4</a> and <a href="https://wg21.link/p2081r1">P2081R1</a>.
</p>


<p><b>Rationale:</b></p>
Resolved by <a href="https://wg21.link/p0325r4">P0325R4</a> and <a href="https://wg21.link/p2081r1">P2081R1</a>.


<p id="res-2814"><b>Proposed resolution:</b></p>





</body>
</html>
