<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2212: tuple_size for const pair request &lt;tuple&gt; header</title>
<meta property="og:title" content="Issue 2212: tuple_size for const pair request &lt;tuple&gt; header">
<meta property="og:description" content="C++ library issue. Status: C++17">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2212.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="2212"><a href="lwg-defects.html#2212">2212</a>. <code>tuple_size</code> for <code>const pair</code> request <code>&lt;tuple&gt;</code> header</h3>
<p><b>Section:</b> 22.2 <a href="https://wg21.link/utility">[utility]</a> <b>Status:</b> <a href="lwg-active.html#C++17">C++17</a>
 <b>Submitter:</b> Alisdair Meredith <b>Opened:</b> 2012-11-09 <b>Last modified:</b> 2017-07-30</p>
<p><b>Priority: </b>3
</p>
<p><b>View all other</b> <a href="lwg-index.html#utility">issues</a> in [utility].</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>
The <code>&lt;utility&gt;</code> header declares sufficient of the tuple API to specialize
the necessary templates for <code>pair</code>, notably <code>tuple_size</code> and
<code>tuple_element</code>.  However, it does not make available the partial specializations
that support cv-qualified template arguments, so while I can write the following after
including only <code>&lt;utility&gt;</code>: 
</p>
<blockquote><pre>
#include &lt;utility&gt;

using TestType = std::pair&lt;int, int&gt;;
static_assert(2 == std::tuple_size&lt;TestType&gt;(), "Pairs have two elements");
std::tuple_element&lt;0, TestType&gt;::type var{1};
</pre></blockquote>
<p>
the following may fail to compile unless I also include <code>&lt;tuple&gt;</code>:
</p>
<blockquote><pre>
#include &lt;utility&gt;

using TestType = const std::pair&lt;int, int&gt;;
static_assert(2 == std::tuple_size&lt;TestType&gt;(), "Pairs have two elements");
std::tuple_element&lt;0, TestType&gt;::type var{1};
</pre></blockquote>
<p>
Note, however, that the latter <em>may</em> compile with some standard library implementations
but not others, leading to subtle portability issues.
</p>

<p><i>[2013-03-15 Issues Teleconference]</i></p>

<p>
Moved to Open.
</p>
<p>
Howard notes that we have the same issue with array, so any resolution should apply to that header too.
</p>

<p><i>[2013-10-18 Daniel provides wording]</i></p>


<p>
The suggested wording uses a similar approach as we already have in 24.7 <a href="https://wg21.link/iterator.range">[iterator.range]</a> to
ensure that the range access templates are available when at least one of an enumerated list of header files is
included.
<p/>
I also think that the restricted focus on <code>tuple_size</code> of this issue is too narrow and should be extended to
the similar partial template specializations of <code>tuple_element</code> as well. Therefore the suggested wording
ensures this as well.
</p>

<p><i>[2014-03-27 Library reflector vote]</i></p>

<p>
The issue has been identified as Tentatively Ready based on eight votes in favour.
</p>



<p id="res-2212"><b>Proposed resolution:</b></p>
<p>This wording is relative to N3936.</p>

<ol>
<li><p>Change 22.4.7 <a href="https://wg21.link/tuple.helper">[tuple.helper]</a> as indicated:</p>

<blockquote><pre>
template &lt;class T&gt; class tuple_size&lt;const T&gt;;
template &lt;class T&gt; class tuple_size&lt;volatile T&gt;;
template &lt;class T&gt; class tuple_size&lt;const volatile T&gt;;
</pre><blockquote>
<p>
-3- Let <code><i>TS</i></code> denote <code>tuple_size&lt;T&gt;</code> of the <i>cv</i>-unqualified type <code>T</code>. Then 
each of the three templates shall meet the <code>UnaryTypeTrait</code> requirements (20.10.1) with a <code>BaseCharacteristic</code> of
</p>
<blockquote><pre>
integral_constant&lt;size_t, <i>TS</i>::value&gt;
</pre></blockquote>
<p>
<ins>-?- In addition to being available via inclusion of the <code>&lt;tuple&gt;</code> header, each of the three templates are
available when any of the headers <code>&lt;array&gt;</code> or <code>&lt;utility&gt;</code> are included.</ins>
</p>
</blockquote></blockquote>

<blockquote><pre>
template &lt;size_t I, class T&gt; class tuple_element&lt;I, const T&gt;;
template &lt;size_t I, class T&gt; class tuple_element&lt;I, volatile T&gt;;
template &lt;size_t I, class T&gt; class tuple_element&lt;I, const volatile T&gt;;
</pre><blockquote>
<p>
<ins>-?-</ins> Let <code><i>TE</i></code> denote <code>tuple_element&lt;I, T&gt;</code> of the <i>cv</i>-unqualified type <code>T</code>. 
Then each of the three templates shall meet the <code>TransformationTrait</code> requirements (20.10.1) with a member typedef 
<code>type</code> that names the following type:
</p>
<ul>
<li><p>
for the first specialization, <code>add_const&lt;<i>TE</i>::type&gt;::type</code>,
</p></li>
<li><p>
for the second specialization, <code>add_volatile&lt;<i>TE</i>::type&gt;::type</code>, and
</p></li>
<li><p>
for the third specialization, <code>add_cv&lt;<i>TE</i>::type&gt;::type</code>.
</p></li>
</ul>
<p>
<ins>-?- In addition to being available via inclusion of the <code>&lt;tuple&gt;</code> header, each of the three templates are
available when any of the headers <code>&lt;array&gt;</code> or <code>&lt;utility&gt;</code> are included.</ins>
</p>
</blockquote></blockquote>
</li>
</ol>






</body>
</html>
