<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2264: [arrays.ts] std::dynarray defines its initializer-list constructor in terms of a non-existent constructor</title>
<meta property="og:title" content="Issue 2264: [arrays.ts] std::dynarray defines its initializer-list constructor in terms of a non-existent constructor">
<meta property="og:description" content="C++ library issue. Status: NAD Arrays">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2264.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#NAD_Arrays">NAD Arrays</a> status.</em></p>
<h3 id="2264"><a href="lwg-closed.html#2264">2264</a>. [arrays.ts] <code>std::dynarray</code> defines its initializer-list constructor in terms of a non-existent constructor</h3>
<p><b>Section:</b> 99 [arrays.ts::dynarray], 99 [arrays.ts::container.requirements] <b>Status:</b> <a href="lwg-active.html#NAD_Arrays">NAD Arrays</a>
 <b>Submitter:</b> Povilas Kanapickas <b>Opened:</b> 2013-05-22 <b>Last modified:</b> 2016-03-08</p>
<p><b>Priority: </b>1
</p>
<p><b>View all issues with</b> <a href="lwg-status.html#NAD Arrays">NAD Arrays</a> status.</p>
<p><b>Discussion:</b></p>
<p><b>Addresses: arrays.ts</b></p>

<p>
<code>std::dynarray</code> member listing at 99 [arrays.ts::dynarray.overview] includes this constructor:
</p>

<blockquote><pre>
dynarray(initializer_list&lt;T&gt;);
</pre></blockquote>

<p>
Also, 99 [arrays.ts::dynarray.overview] p. 2 says:
</p>

<blockquote><p>
Unless otherwise specified, all <code>dynarray</code> operations have the same requirements and semantics as specified in 23.2.
</p></blockquote>

<p>
The constructor in question isn't mentioned in 99 [arrays.ts::dynarray.cons] or anywhere else. This means requirements from 
99 [arrays.ts::container.requirements] apply. However, Table 100 in 23.2.4 <a href="https://wg21.link/sequence.reqmts">[sequence.reqmts]</a> says:
</p>

<blockquote><p>
<code>X(il)</code> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Equivalent to <code>X(il.begin(), il.end())</code>      
</p></blockquote>

<p>
<code>std::dynarray</code> does not provide this constructor.
</p>

<p>
The proposed resolution below adds the missing constructor and a complementary constructor with an allocator parameter. 
The new constructors, differently from the rest of containers, accept iterators that have forward iterator category. This 
is needed because the size requirements must be known in order to allocate appropriately-sized storage.
<p/>
An alternative resolution could be to properly specify the initializer-list constructor.
</p>

<p><i>[2013-09 Chicago:]</i></p>

<p>
Move to Deferred. This feature will ship after C++14 and should be revisited then.
</p>

<p><i>[2014-06-06 pre-Rapperswill]</i></p>

<p>
This issue has been reopened as arrays-ts.
</p>



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

<ol>
<li><p>Add the following to the <code>std::dynarray</code> synopsis at 99 [arrays.ts::dynarray.overview]:</p>

<blockquote><pre>
namespace std {
  template &lt;class T&gt;
  class dynarray {
    [&hellip;]
    <i>// 23.3.4.2 construct/copy/destroy:</i>
    [&hellip;]
    <ins>template &lt;class ForwardIterator&gt;</ins>
    <ins>dynarray(ForwardIterator first, ForwardIterator last);</ins>
    <ins>template &lt;class ForwardIterator, class Alloc&gt;</ins>
    <ins>dynarray(ForwardIterator first, ForwardIterator last, const Alloc&amp; alloc);</ins>
    [&hellip;]
  };
}
</pre></blockquote>
</li>

<li><p>Add the following to 99 [arrays.ts::dynarray.cons] after p. 8:</p>

<blockquote><pre>
<ins>template &lt;class ForwardIterator&gt;
dynarray(ForwardIterator first, ForwardIterator last);</ins>
</pre><blockquote>
<p>
<ins>-?-  <i>Requires:</i> <code>T</code> shall meet the <code>CopyConstructible</code> requirements.</ins>
<p/>
<ins>-?-  <i>Effects:</i> Allocates storage for <code>distance(first, last)</code> elements.
The <code>distance(first, last)</code> elements of the dynarray are direct-initialized (9.5 <a href="https://wg21.link/dcl.init">[dcl.init]</a>) with the 
corresponding elements from the range <code>[first,last)</code>. May or may not invoke the global <code>operator new</code>.</ins>
<p/>
<ins>-?-  <i>Complexity:</i> <code>distance(first, last)</code>.</ins>
<p/>
<ins>-?-  <i>Throws:</i> <code>std::bad_array_length</code> when the size requested is larger than implementable, <code>std::bad_alloc</code> 
when there is insufficient memory.</ins>
</p>
</blockquote></blockquote>
</li>

<li><p>Add the following to the list of constructors at 99 [arrays.ts::dynarray.cons] before p. 9:</p>

<blockquote><pre>
template &lt;class Alloc&gt;
dynarray(size_type c, const Alloc&amp; alloc);
template &lt;class Alloc&gt;
dynarray(size_type c, const T&amp; v, const Alloc&amp; alloc);
template &lt;class Alloc&gt;
dynarray(const dynarray&amp; d, const Alloc&amp; alloc);
template &lt;class Alloc&gt;
dynarray(initializer_list&lt;T&gt;, const Alloc&amp; alloc);
<ins>template &lt;class ForwardIterator, class Alloc&gt;
dynarray(ForwardIterator first, ForwardIterator last, const Alloc&amp; alloc);</ins>
</pre></blockquote>
</li>
</ol>






</body>
</html>
