<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 396: what are characters zero and one</title>
<meta property="og:title" content="Issue 396: what are characters zero and one">
<meta property="og:description" content="C++ library issue. Status: CD1">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue396.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#CD1">CD1</a> status.</em></p>
<h3 id="396"><a href="lwg-defects.html#396">396</a>. what are characters zero and one</h3>
<p><b>Section:</b> 22.9.2.2 <a href="https://wg21.link/bitset.cons">[bitset.cons]</a> <b>Status:</b> <a href="lwg-active.html#CD1">CD1</a>
 <b>Submitter:</b> Martin Sebor <b>Opened:</b> 2003-01-05 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all other</b> <a href="lwg-index.html#bitset.cons">issues</a> in [bitset.cons].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#CD1">CD1</a> status.</p>
<p><b>Discussion:</b></p>
    <p>
23.3.5.1, p6 [lib.bitset.cons] talks about a generic character
having the value of 0 or 1 but there is no definition of what
that means for charT other than char and wchar_t. And even for
those two types, the values 0 and 1 are not actually what is
intended -- the values '0' and '1' are. This, along with the
converse problem in the description of to_string() in 23.3.5.2,
p33, looks like a defect remotely related to DR <a href="lwg-defects.html#303" title="Bitset input operator underspecified (Status: CD1)">303</a><sup><a href="https://cplusplus.github.io/LWG/issue303" title="Latest snapshot">(i)</a></sup>.
    </p>
    <pre>
23.3.5.1:
  -6-  An element of the constructed string has value zero if the
       corresponding character in str, beginning at position pos,
       is 0. Otherwise, the element has the value one.
    </pre>
    <pre>
23.3.5.2:
  -33-  Effects: Constructs a string object of the appropriate
        type and initializes it to a string of length N characters.
        Each character is determined by the value of its
        corresponding bit position in *this. Character position N
        ?- 1 corresponds to bit position zero. Subsequent decreasing
        character positions correspond to increasing bit positions.
        Bit value zero becomes the character 0, bit value one becomes
        the character 1.
    </pre>
    <p>
Also note the typo in 23.3.5.1, p6: the object under construction
is a bitset, not a string.
    </p>

<p><i>[
Sophia Antipolis:
]</i></p>


<blockquote>
<p>
We note that <code>bitset</code> has been moved from section 23 to section 20, by
another issue (<a href="lwg-defects.html#842" title="ConstructibleAsElement and bit containers (Status: CD1)">842</a><sup><a href="https://cplusplus.github.io/LWG/issue842" title="Latest snapshot">(i)</a></sup>) previously resolved at this meeting.
</p>
<p>
Disposition: move to ready.
</p>
<p>
We request that Howard submit a separate issue regarding the three <code>to_string</code> overloads.
</p>
</blockquote>

<p><i>[
post Bellevue:
]</i></p>


<blockquote><p>
We are happy with the resolution as proposed, and we move this to Ready.
</p></blockquote>

<p><i>[
Howard adds:
]</i></p>


<blockquote><p>
The proposed wording neglects the 3 newer <code>to_string</code> overloads.
</p></blockquote>



<p id="res-396"><b>Proposed resolution:</b></p>
<p>Change the constructor's function declaration immediately before 
22.9.2.2 <a href="https://wg21.link/bitset.cons">[bitset.cons]</a> p3 to:</p>
<pre>
    template &lt;class charT, class traits, class Allocator&gt;
    explicit
    bitset(const basic_string&lt;charT, traits, Allocator&gt;&amp; str,
           typename basic_string&lt;charT, traits, Allocator&gt;::size_type pos = 0,
           typename basic_string&lt;charT, traits, Allocator&gt;::size_type n =
             basic_string&lt;charT, traits, Allocator&gt;::npos,
           charT zero = charT('0'), charT one = charT('1'))
</pre>
<p>Change the first two sentences of 22.9.2.2 <a href="https://wg21.link/bitset.cons">[bitset.cons]</a> p6 to: "An
element of the constructed string has value 0 if the corresponding
character in <i>str</i>, beginning at position <i>pos</i>,
is <i>zero</i>. Otherwise, the element has the value 1.</p>

<p>Change the text of the second sentence in 23.3.5.1, p5 to read:
    "The function then throws invalid_argument if any of the rlen
    characters in str beginning at position pos is other than <i>zero</i>
    or <i>one</i>. The function uses traits::eq() to compare the character
    values."
</p>

<p>Change the declaration of the <code>to_string</code> member function
  immediately before 22.9.2.3 <a href="https://wg21.link/bitset.members">[bitset.members]</a> p33 to:</p>
<pre>
    template &lt;class charT, class traits, class Allocator&gt;
    basic_string&lt;charT, traits, Allocator&gt; 
    to_string(charT zero = charT('0'), charT one = charT('1')) const;
</pre>
<p>Change the last sentence of 22.9.2.3 <a href="https://wg21.link/bitset.members">[bitset.members]</a> p33 to: "Bit
  value 0 becomes the character <code><i>zero</i></code>, bit value 1 becomes the
  character <code><i>one</i></code>.</p>
<p>Change 22.9.4 <a href="https://wg21.link/bitset.operators">[bitset.operators]</a> p8 to:</p>
<p><b>Returns</b>:</p> 
<pre>
  os &lt;&lt; x.template to_string&lt;charT,traits,allocator&lt;charT&gt; &gt;(
      use_facet&lt;ctype&lt;charT&gt; &gt;(<i>os</i>.getloc()).widen('0'),
      use_facet&lt;ctype&lt;charT&gt; &gt;(<i>os</i>.getloc()).widen('1'));
</pre>


<p><b>Rationale:</b></p>
<p>There is a real problem here: we need the character values of '0'
  and '1', and we have no way to get them since strings don't have
  imbued locales. In principle the "right" solution would be to
  provide an extra object, either a ctype facet or a full locale,
  which would be used to widen '0' and '1'. However, there was some
  discomfort about using such a heavyweight mechanism.  The proposed
  resolution allows those users who care about this issue to get it
  right.</p>
<p>We fix the inserter to use the new arguments.  Note that we already
  fixed the analogous problem with the extractor in issue <a href="lwg-defects.html#303" title="Bitset input operator underspecified (Status: CD1)">303</a><sup><a href="https://cplusplus.github.io/LWG/issue303" title="Latest snapshot">(i)</a></sup>.</p>





</body>
</html>
