<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3694: Should traits_type::length be customizable?</title>
<meta property="og:title" content="Issue 3694: Should traits_type::length be customizable?">
<meta property="og:description" content="C++ library issue. Status: New">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3694.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="3694"><a href="lwg-active.html#3694">3694</a>. Should <code>traits_type::length</code> be customizable?</h3>
<p><b>Section:</b> 27.2.2 <a href="https://wg21.link/char.traits.require">[char.traits.require]</a> <b>Status:</b> <a href="lwg-active.html#New">New</a>
 <b>Submitter:</b> Jiang An <b>Opened:</b> 2022-05-04 <b>Last modified:</b> 2022-05-17</p>
<p><b>Priority: </b>4
</p>
<p><b>View other</b> <a href="lwg-index-open.html#char.traits.require">active issues</a> in [char.traits.require].</p>
<p><b>View all other</b> <a href="lwg-index.html#char.traits.require">issues</a> in [char.traits.require].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#New">New</a> status.</p>
<p><b>Discussion:</b></p>
<p>
MSVC STL's implementation of the <code>std::quoted</code> overload for <code>const charT*</code> calculates 
the length of the NTCTS and stores the result within the return value. Because the returned value may  
be output by <code>std::basic_ostream</code> specializations with different <code>traits_type</code>s, this 
strategy can be conforming only if all possible <code>traits_type::length</code> functions for the same 
<code>char_type</code> have equivalent return values.
<p/>
It seems not clear whether <code>traits_type::length</code> should be customizable. In a related PR, 
<a href="https://github.com/microsoft/STL/pull/2676#discussion_r861407001">Stephan T. Lavavej said</a> :
</p>
<blockquote style="border-left: 3px solid #ccc;padding-left: 15px;">
<p>
I argue that you've found a defect in the <code>char_traits</code> specification &mdash; it should say 
that whatever <code>eq()</code> does, it should consider <code>charT()</code> to be distinct from all other 
values, which aligns with the common understanding of how null-terminated strings behave.
<p/>
The original implementation and the <code>char_traits::length</code> change both handle arbitrary character 
types &mdash; the only difference would be for custom <code>char_traits</code> that consider null terminators 
to be equal to other values, which I have never seen used in practice (e.g. case-insensitive traits 
don't do this).
</p>
</blockquote>
<p>
If it is decided that <code>traits_type::length</code> is customizable, then the implementation in MSVC STL 
should be fixed. Otherwise, we should explicitly require in 27.2.2 <a href="https://wg21.link/char.traits.require">[char.traits.require]</a> that 
whenever <code>c</code> is not "equal" to <code>char_type()</code>, <code>traits_type::eq(c, char_type())</code> is 
<code>false</code>.
<p/>
However, equivalence of two <code>charT</code> values seems not easy to specify, as there may be no 
<code>operator==</code> for <code>charT</code>, or the <code>operator==</code> behaves pathologically. IMO possible 
way may be
</p>
<ul>
<li><p>using the equivalence relation of value representations, or</p></li>
<li><p>using <code>==</code> and only imposing the requirement when <code>char_type</code> is an encoded 
character type (or more generally, a scalar type, while treating an enum type as its underlying type).</p></li>
</ul>

<p><i>[2022-05-17; Reflector poll]</i></p>

<p>
Set priority to 4 after reflector poll. One vote for NAD.
</p>



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





</body>
</html>
