<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3382: NTTP for pair and array</title>
<meta property="og:title" content="Issue 3382: NTTP for pair and array">
<meta property="og:description" content="C++ library issue. Status: C++20">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3382.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++20">C++20</a> status.</em></p>
<h3 id="3382"><a href="lwg-defects.html#3382">3382</a>. NTTP for <code>pair</code> and <code>array</code></h3>
<p><b>Section:</b> 22.3.2 <a href="https://wg21.link/pairs.pair">[pairs.pair]</a>, 23.3.3 <a href="https://wg21.link/array">[array]</a> <b>Status:</b> <a href="lwg-active.html#C++20">C++20</a>
 <b>Submitter:</b> Barry Revzin <b>Opened:</b> 2020-01-27 <b>Last modified:</b> 2021-02-25</p>
<p><b>Priority: </b>2
</p>
<p><b>View other</b> <a href="lwg-index-open.html#pairs.pair">active issues</a> in [pairs.pair].</p>
<p><b>View all other</b> <a href="lwg-index.html#pairs.pair">issues</a> in [pairs.pair].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++20">C++20</a> status.</p>
<p><b>Discussion:</b></p>
<p>
We had <a href="https://github.com/cplusplus/nbballot/issues/235">this NB ballot issue</a>, to ensure that 
<code>std::array</code> could be a NTTP. But after <a href="https://wg21.link/p1907">P1907</a>, we still need 
some kind of wording to ensure that <code>std::array</code> (and also <code>std::pair</code>) have no extra 
private members or base classes.
<p/>
This is similar to LWG <a href="lwg-defects.html#3373" title="{to,from}_chars_result and format_to_n_result need the
 &quot;we really mean what we say&quot; wording (Status: C++20)">3373</a><sup><a href="https://cplusplus.github.io/LWG/issue3373" title="Latest snapshot">(i)</a></sup> &mdash; maybe we just need to add:
</p>
<blockquote><p>
The class template <code>pair</code>/<code>array</code> has the data members specified above. It has no base 
classes or data members other than those specified.
</p></blockquote>

<p><i>[2020-02 Prioritized as P2 Monday morning in Prague]</i></p>


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

<ol>
<li><p>Modify 22.3.2 <a href="https://wg21.link/pairs.pair">[pairs.pair]</a> as indicated:</p>

<blockquote>
<p>
-1- Constructors and member functions of <code>pair</code> do not throw exceptions unless one of the element-wise 
operations specified to be called for that operation throws an exception.
<p/>
-2- The defaulted move and copy constructor, respectively, of <code>pair</code> is a constexpr function if and 
only if all required element-wise initializations for copy and move, respectively, would satisfy the 
requirements for a constexpr function.
<p/>
-3- If <code>(is_trivially_destructible_v&lt;T1&gt; &amp;&amp; is_trivially_destructible_v&lt;T2&gt;)</code> 
is <code>true</code>, then the destructor of <code>pair</code> is trivial.
<p/>
<ins>-?- The class template <code>pair</code> has the data members specified above. It has no base classes or 
data members other than those specified.</ins>
</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>
-1- The header <code>&lt;array&gt;</code> defines a class template for storing fixed-size sequences of objects. 
An <code>array</code> is a contiguous container (23.2.2 <a href="https://wg21.link/container.requirements.general">[container.requirements.general]</a>). An instance of 
<code>array&lt;T, N&gt;</code> stores <code>N</code> elements of type <code>T</code>, so that <code>size() == N</code> is 
an invariant.
<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- An <code>array</code> meets 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</code> object is not empty 
and that <code>swap</code> does not have constant complexity. 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/>
<ins>-?- The class template <code>array</code> has the data members specified in subclauses 
23.3.3.1 <a href="https://wg21.link/array.overview">[array.overview]</a> and 23.3.3.5 <a href="https://wg21.link/array.zero">[array.zero]</a>. It has no base classes or 
data members other than those specified.</ins>
<p/>
-4- [&hellip;]
</p>
</blockquote>
</li>
</ol>
</blockquote>

<p><i>[2020-02-13, Prague]</i></p>

<p>
Tim Song and Tomasz were trying to come up with general wording that could be reused for both <code>pair</code> and 
<code>array</code> (and other types). They suggest that if it should be in scope for C++20, it would be better to 
provide non-general wording for <code>pair</code> and <code>array</code> (that is easier to get right).
<p/>
For completeness (and future wording) the generalized wording is included. The definition of <i>structurally compatible with</i>:
</p>
<blockquote><p>
The type <code>T</code> is <em>structurally compatible with</em> <code><i>subs</i></code>, if for the values 
<code>t1</code> and <code>t2</code> of type <code>T</code>:
</p>
<ul>
 <li><p><code>T</code> is a structural type (13.2 <a href="https://wg21.link/temp.param">[temp.param]</a>) if the types of subobjects of <code>t1</code> 
 designated by <code><i>subs</i></code> are all structural types.</p></li>
 <li><p><code>t1</code> is template-argument-equivalent (13.6 <a href="https://wg21.link/temp.type">[temp.type]</a>) to <code>t2</code>, 
 if and only if, for each subject designed by  <code><i>subs</i></code>, the value of subobject 
 of <code>t1</code> is template-argument-equivalent to the value of the correponding subobject of 
 <code>t2</code>.</p></li>
</ul>
</blockquote>
<p>
Then changes for <code>array</code>/<code>pair</code> would then look like:
</p>
<blockquote>
<p>
<code>pair&lt;T, U&gt;</code> is structurally compatible (&lt;some-reference&gt;) with <code>first</code> and <code>second</code>.
<p/>
<code>array&lt;T, N&gt;</code> is structurally compatible with its elements (if any).
</p>
</blockquote>

<p><i>[2020-02 Status to Immediate on Friday morning in Prague.]</i></p>



<p id="res-3382"><b>Proposed resolution:</b></p>
<p>This wording is relative to <a href="https://wg21.link/n4849">N4849</a>.</p>

<ol>
<li><p>Modify 22.3.2 <a href="https://wg21.link/pairs.pair">[pairs.pair]</a> as indicated:</p>

<blockquote>
<p>
-1- Constructors and member functions of <code>pair</code> do not throw exceptions unless one of the element-wise 
operations specified to be called for that operation throws an exception.
<p/>
-2- The defaulted move and copy constructor, respectively, of <code>pair</code> is a constexpr function if and 
only if all required element-wise initializations for copy and move, respectively, would satisfy the 
requirements for a constexpr function.
<p/>
-3- If <code>(is_trivially_destructible_v&lt;T1&gt; &amp;&amp; is_trivially_destructible_v&lt;T2&gt;)</code> 
is <code>true</code>, then the destructor of <code>pair</code> is trivial.
<p/>
<ins>-?- <code>pair&lt;T, U&gt;</code> is a structural type (13.2 <a href="https://wg21.link/temp.param">[temp.param]</a>) if <code>T</code> 
and <code>U</code> are both structural types. Two values <code>p1</code> and <code>p2</code> of type 
<code>pair&lt;T, U&gt;</code> are template-argument-equivalent (13.6 <a href="https://wg21.link/temp.type">[temp.type]</a>) if and only if 
<code>p1.first</code> and <code>p2.first</code> are template-argument-equivalent and <code>p1.second</code> 
and <code>p2.second</code> are template-argument-equivalent.</ins>
</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>
-1- The header <code>&lt;array&gt;</code> defines a class template for storing fixed-size sequences of objects. 
An <code>array</code> is a contiguous container (23.2.2 <a href="https://wg21.link/container.requirements.general">[container.requirements.general]</a>). An instance of 
<code>array&lt;T, N&gt;</code> stores <code>N</code> elements of type <code>T</code>, so that <code>size() == N</code> is 
an invariant.
<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- An <code>array</code> meets 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</code> object is not empty 
and that <code>swap</code> does not have constant complexity. 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/>
<ins>-?- <code>array&lt;T, N&gt;</code> is a structural type (13.2 <a href="https://wg21.link/temp.param">[temp.param]</a>) if <code>T</code> 
is a structural type. Two values <code>a1</code> and <code>a2</code> of type <code>array&lt;T, N&gt;</code> 
are template-argument-equivalent (13.6 <a href="https://wg21.link/temp.type">[temp.type]</a>) if and only if each pair of corresponding 
elements in <code>a1</code> and <code>a2</code> are template-argument-equivalent.</ins>
<p/>
-4- [&hellip;]
</p>
</blockquote>
</li>
</ol>





</body>
</html>
