<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3219: std::array overview container requirements are incorrect</title>
<meta property="og:title" content="Issue 3219: std::array overview container requirements are incorrect">
<meta property="og:description" content="C++ library issue. Status: New">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3219.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#New">New</a> status.</em></p>
<h3 id="3219"><a href="lwg-active.html#3219">3219</a>. <code>std::array</code> overview container requirements are incorrect</h3>
<p><b>Section:</b> 23.3.3.1 <a href="https://wg21.link/array.overview">[array.overview]</a>, 23.2.2 <a href="https://wg21.link/container.requirements.general">[container.requirements.general]</a> <b>Status:</b> <a href="lwg-active.html#New">New</a>
 <b>Submitter:</b> Nevin Liber &amp; Christian Trott <b>Opened:</b> 2019-06-13 <b>Last modified:</b> 2022-04-24</p>
<p><b>Priority: </b>3
</p>
<p><b>View other</b> <a href="lwg-index-open.html#array.overview">active issues</a> in [array.overview].</p>
<p><b>View all other</b> <a href="lwg-index.html#array.overview">issues</a> in [array.overview].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#New">New</a> status.</p>
<p><b>Discussion:</b></p>
<p>
The requirements specified in 23.3.3.1 <a href="https://wg21.link/array.overview">[array.overview]</a> p3 are incorrect; namely:
</p>
<ul>
<li><p>A default constructed <code>array&lt;T, N&gt;</code> where <code>0 &lt; N</code> has linear,
not constant complexity.</p></li>
<li><p>A default constructed <code>array&lt;T, 0&gt;</code> is empty and has constant complexity.</p></li>
</ul>

<p><i>[2019-07 Issue Prioritization]</i></p>

<p>Priority to 3 after discussion on the reflector.</p>

<p>
<strong>Previous resolution [SUPERSEDED]:</strong>
</p>
<blockquote class="note">
<p>This wording is relative to <a href="https://wg21.link/N4810" title=" Working Draft, Standard for Programming Language C++">N4810</a>.</p>

<ol>
<li><p>Modify 23.2.2 <a href="https://wg21.link/container.requirements.general">[container.requirements.general]</a>, Table 62 &mdash; "Container requirements",
as indicated (This table can be identified by the "section" identifier [tab:container.req] in the next
working draft):</p>

<blockquote>
<table border="1">
<caption>Table 62 &mdash; Container requirements</caption>
<tr style="text-align:center">
<th>Expression</th>
<th>Return type</th>
<th>Operational<br/>semantics</th>
<th>Assertion/note<br/>pre/post-condition</th>
<th>Complexity</th>
</tr>
<tr>
<td colspan="5" align="center">
<code>[&hellip;]</code>
</td>
</tr>
<tr>
<td>
<code>X u;</code>
</td>
<td>
<code></code>
</td>
<td></td>
<td>
<ins><i>Ensures:</i> <code>!u.empty()</code> for <code>array&lt;T, N&gt;</code> where <code>0 &lt; N</code>, and</ins><br/>
<i>Ensures:</i> <code>u.empty()</code> <ins>for all other standard containers.</ins>
</td>
<td>
<del>constant</del><ins>(Note A)</ins>
</td>
</tr>
<tr>
<td>
<code>X()</code>
</td>
<td>
<code></code>
</td>
<td></td>
<td>
<ins><i>Ensures:</i> <code>!X().empty()</code> for <code>array&lt;T, N&gt;</code> where <code>0 &lt; N</code>, and</ins><br/>
<i>Ensures:</i> <code>X().empty()</code> <ins>for all other standard containers.</ins>
</td>
<td>
<del>constant</del><ins>(Note A)</ins>
</td>
</tr>

<tr>
<td colspan="5" align="center">
<code>[&hellip;]</code>
</td>
</tr>
</table>
<p>
Those entries marked "(Note A)" or "(Note B)" have linear complexity for <code>array<ins>&lt;T, N&gt;</ins></code>
<ins>where <code>0 &lt; N</code></ins> and have constant complexity for all other standard containers.
</p>
</blockquote>

</li>

<li><p>Modify 23.3.3.1 <a href="https://wg21.link/array.overview">[array.overview]</a> as indicated:</p>

<blockquote>
<p>
-2- An <code>array</code> is an aggregate (9.5.2 <a href="https://wg21.link/dcl.init.aggr">[dcl.init.aggr]</a>) that can be list-initialized with up to
<code>N</code> elements whose types are convertible to <code>T</code>.
<p/>
-3- <ins>An <code>array&lt;T, 0&gt;</code> satisfies all of the requirements of a container and of a
reversible container (23.2 <a href="https://wg21.link/container.requirements">[container.requirements]</a>).</ins> An
<code>array<ins>&lt;T, N&gt;</ins></code> <ins>where <code>0 &lt; N</code></ins> satisfies all
of the requirements of a container and of a reversible container
(23.2 <a href="https://wg21.link/container.requirements">[container.requirements]</a>), except that a default constructed
<code>array<ins>&lt;T, N&gt;</ins></code> object is not empty and <del>that</del><ins>both default
construction and</ins> <code>swap</code> <del>does not</del> have <del>constant</del><ins>linear</ins>
complexity. An <code>array</code> satisfies some of the requirements of a sequence container
(23.2.4 <a href="https://wg21.link/sequence.reqmts">[sequence.reqmts]</a>). Descriptions are provided here only for operations on
<code>array</code> that are not described in one of these tables and for operations where there is
additional semantic information.
</p>
</blockquote>

</li>
</ol>
</blockquote>

<p><i>[2022-04-24; Daniel rebases wording on <a href="https://wg21.link/N4910" title=" Working Draft, Standard for Programming Language C++">N4910</a>]</i></p>



<p id="res-3219"><b>Proposed resolution:</b></p>
<p>
This wording is relative to <a href="https://wg21.link/N4910" title=" Working Draft, Standard for Programming Language C++">N4910</a>.
</p>

<ol>
<li><p>Modify 23.2.2.2 <a href="https://wg21.link/container.reqmts">[container.reqmts]</a> as indicated:</p>

<blockquote>
<pre>
X u;
X u = X();
</pre>
<blockquote>
<p>
-10- <i>Postconditions:</i> <ins><code>!u.empty()</code> for <code>array&lt;T, N&gt;</code> where <code>0 &lt; N</code>, 
and</ins> <code>u.empty()</code> <ins>for all other standard containers.</ins>
<p/>
-11- <i>Complexity:</i> <del>Constant</del><ins>Linear for <code>array&lt;T, N&gt;</code> where <code>0 &lt; N</code> 
and constant for all other standard containers</ins>.
</p>
</blockquote>
[&hellip;]
<pre>
X u(rv);
X u = rv;
</pre>
<blockquote>
<p>
-15- <i>Postconditions:</i> <code>u</code> is equal to the value that <code>rv</code> had before this construction.
<p/>
-11- <i>Complexity:</i> Linear for <code>array<ins>&lt;T, N&gt;</ins></code> <ins>where <code>0 &lt; N</code></ins> and 
constant for all other standard containers.
</p>
</blockquote>
[&hellip;]
<pre>
a.swap(b)
</pre>
<blockquote>
<p>
-45- <i>Result:</i> <code>void</code>
<p/>
-46- <i>Effects:</i> Exchanges the contents of <code>a</code> and <code>b</code>.
<p/>
-47- <i>Complexity:</i> Linear for <code>array<ins>&lt;T, N&gt;</ins></code> <ins>where <code>0 &lt; N</code></ins> and 
constant for all other standard containers.
</p>
</blockquote>
</blockquote>
</li>

<li><p>Modify 23.3.3.1 <a href="https://wg21.link/array.overview">[array.overview]</a> as indicated:</p>

<blockquote>
<p>
-2- An <code>array</code> is an aggregate (9.5.2 <a href="https://wg21.link/dcl.init.aggr">[dcl.init.aggr]</a>) that can be list-initialized with up to
<code>N</code> elements whose types are convertible to <code>T</code>.
<p/>
-3- <ins>An <code>array&lt;T, 0&gt;</code> meets all of the requirements of a container (23.2.2.2 <a href="https://wg21.link/container.reqmts">[container.reqmts]</a>) 
and of a reversible container (23.2.2.3 <a href="https://wg21.link/container.rev.reqmts">[container.rev.reqmts]</a>).</ins> An
<code>array<ins>&lt;T, N&gt;</ins></code> <ins>where <code>0 &lt; N</code></ins> meets all
of the requirements of a container (23.2.2.2 <a href="https://wg21.link/container.reqmts">[container.reqmts]</a>) and of a reversible container
(23.2.2.3 <a href="https://wg21.link/container.rev.reqmts">[container.rev.reqmts]</a>), except that a default constructed
<code>array<ins>&lt;T, N&gt;</ins></code> object is not empty if <code>N &gt; 0</code> <ins>and default
construction, move construction, and <code>swap</code> have linear complexity if <code>N &gt; 0</code></ins>. 
An <code>array</code> meets some of the requirements of a sequence container (23.2.4 <a href="https://wg21.link/sequence.reqmts">[sequence.reqmts]</a>). 
Descriptions are provided here only for operations on <code>array</code> that are not described in one of these 
tables and for operations where there is additional semantic information.
</p>
</blockquote>

</li>
</ol>




</body>
</html>
