<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 4040: Contradictory specification of std::tuple_size</title>
<meta property="og:title" content="Issue 4040: Contradictory specification of std::tuple_size">
<meta property="og:description" content="C++ library issue. Status: New">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue4040.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="4040"><a href="lwg-active.html#4040">4040</a>. Contradictory specification of <code>std::tuple_size</code></h3>
<p><b>Section:</b> 22.4.7 <a href="https://wg21.link/tuple.helper">[tuple.helper]</a> <b>Status:</b> <a href="lwg-active.html#New">New</a>
 <b>Submitter:</b> Jiang An <b>Opened:</b> 2024-01-20 <b>Last modified:</b> 2024-03-11</p>
<p><b>Priority: </b>3
</p>
<p><b>View all other</b> <a href="lwg-index.html#tuple.helper">issues</a> in [tuple.helper].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#New">New</a> status.</p>
<p><b>Discussion:</b></p>
<p>
22.4.7 <a href="https://wg21.link/tuple.helper">[tuple.helper]</a>/1 currently says:
</p>
<blockquote>
<p>
All specializations of <code>tuple_size</code> meet the <i>Cpp17UnaryTypeTrait</i> requirements 
(21.3.2 <a href="https://wg21.link/meta.rqmts">[meta.rqmts]</a>) with a base characteristic of <code>integral_constant&lt;size_t, N&gt;</code> 
for some <code>N</code>.
</p>
</blockquote>
<p>
which is probably wrong for <code>std::tuple_size&lt;int&gt;</code> and 
<code>std::tuple_size&lt;std::vector&lt;int&gt;&gt;</code> whose definitions are not provided, and 
contradicts with 22.4.7 <a href="https://wg21.link/tuple.helper">[tuple.helper]</a>/4
</p>
<blockquote>
<p>
[&hellip;] Otherwise, it has no member <code>value</code>.
</p>
</blockquote>
<p>
Also, there's currently implementation divergence on whether <code>std::tuple_size&lt;<i>cv</i> T&gt;</code> 
is a complete type when <code>std::tuple_size&lt;T&gt;::value</code> is absent (related to LWG <a href="lwg-defects.html#2770" title="tuple_size&lt;const T&gt; specialization is not SFINAE compatible and breaks decomposition declarations (Status: C++17)">2770</a><sup><a href="https://cplusplus.github.io/LWG/issue2770" title="Latest snapshot">(i)</a></sup>). 
Some implementations (e.g. 
<a href="https://github.com/llvm/llvm-project/blob/b1d4265a5f5345065e5c2aedf50787da05ddcc08/libcxx/include/__tuple/tuple_size.h#L29-L47">libc++</a> 
and <a href="https://github.com/gcc-mirror/gcc/blob/615e25c82de97acc17ab438f88d6788cf7ffe1d6/libstdc%2B%2B-v3/include/bits/utility.h#L55-L71">libstdc++</a>) 
treat 22.4.7 <a href="https://wg21.link/tuple.helper">[tuple.helper]</a>/4 and D.15 <a href="https://wg21.link/depr.tuple">[depr.tuple]</a>/2 as "<code>std::tuple_size&lt;<i>cv</i> T&gt;</code> 
is generated from partial specializations only if <code>std::tuple_size&lt;T&gt;</code> meets the aforementioned conditions", 
while others (e.g. <a href="https://github.com/microsoft/STL/blob/442029c6fa37f1b6f9203357de09672d5704077c/stl/inc/utility#L598-L612">MSVC STL</a>) 
always consider <code>std::tuple_size&lt;<i>cv</i> T&gt;</code> needs to be defined. The latter 
reading seems to be justified by 16.4.2.2 <a href="https://wg21.link/contents">[contents]</a>/1 and 22.4.2 <a href="https://wg21.link/tuple.syn">[tuple.syn]</a>.
</p>

<p><i>[2024-03-11; Reflector poll]</i></p>

<p>
Set priority to 3 after reflector poll.
The first part of the issue was
<a href="https://github.com/cplusplus/draft/pull/6777">fixed editorially</a>.
</p>



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





</body>
</html>
