<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 1112: bitsets and new style for loop</title>
<meta property="og:title" content="Issue 1112: bitsets and new style for loop">
<meta property="og:description" content="C++ library issue. Status: NAD">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue1112.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#NAD">NAD</a> status.</em></p>
<h3 id="1112"><a href="lwg-closed.html#1112">1112</a>. bitsets and new style for loop</h3>
<p><b>Section:</b> 22.9.2 <a href="https://wg21.link/template.bitset">[template.bitset]</a> <b>Status:</b> <a href="lwg-active.html#NAD">NAD</a>
 <b>Submitter:</b> Alisdair Meredith <b>Opened:</b> 2009-05-06 <b>Last modified:</b> 2018-06-23</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View other</b> <a href="lwg-index-open.html#template.bitset">active issues</a> in [template.bitset].</p>
<p><b>View all other</b> <a href="lwg-index.html#template.bitset">issues</a> in [template.bitset].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#NAD">NAD</a> status.</p>
<p><b>Discussion:</b></p>
<p>
<code>std::bitset</code> is a homogeneous container-like sequence of bits, yet it does
not model the Range concept so cannot be used with the new for-loop syntax.
It is the only such type in the library that does NOT support the new for
loop.
</p>
<p>
The obvious reason is that bitset does not support iterators.
</p>
<p>
At least two reasonable solutions are available:
</p>
<ol style="list-style-type:lower-roman">
<li>
Add an iterator interface to <code>bitset</code>, bringing its interface close to that
of <code>std::array</code>
</li>
<li>
Provide an unspecified concept_map for <code>Range&lt;bitset&gt;</code>.
</li>
</ol>
<p>
The latter will still need some kind of iterator-like adapter for <code>bitset</code>,
but gives implementers greater freedom on the details. E.g. begin/end return
some type that simply invokes <code>operator[]</code> on the object it wraps, and
increments its index on <code>operator++</code>.  A vendor can settle for <code>InputIterator</code>
support, rather than wrapping up a full <code>RandomAccessIterator</code>.
</p>
<p>
I have a mild preference for option (ii) as I think it is less work to
specify at this stage of the process, although (i) is probably more useful
in the long run.
</p>
<p>
Hmm, my wording looks a little woolly, as it does not say what the element
type of the range is.  Do I get a range of <code>bool</code>, <code>bitset&lt;N&gt;::reference</code>, or
something else entirely?
</p>
<p>
I guess most users will assume the behaviour of reference, but expect to
work with <code>bool</code>.  <code>Bool</code> is OK for read-only traversal, but you really need to
take a reference to a <code>bitset::reference</code> if you want to write back.
</p>

<p><i>[
Batavia (2009-05):
]</i></p>

<blockquote><p>
Move to Open.
We further recommend this be deferred until after the next Committee Draft.
</p></blockquote>

<p><i>[
2009-05-25 Alisdair adds:
]</i></p>


<blockquote>
<p>
I just stumbled over the <code>Range concept_map</code> for <code>valarray</code> and this should
probably set the precedent on how to write the wording.
</p>

<p><i>[
Howard: I've replaced the proposed wording with Alisdair's suggestion.
]</i></p>


</blockquote>

<p><i>[
2009-07-24 Daniel modifies the proposed wording for non-concepts.
]</i></p>


<p><i>[
2009-10 post-Santa Cruz:
]</i></p>


<blockquote><p>
Mark as Tentatively NAD Future due to the loss of concepts.
</p></blockquote>

<p><i>[2017-02 in Kona, LEWG recommends NAD]</i></p>

<p>There are better APIs for bits coming, and seems to be consensus
in LEWG not to polish bitset any further.</p>

<p><i>[2017-06-02 Issues Telecon]</i></p>

<p>Resolve as NAD</p>


<p><b>Rationale:</b></p>
<p>
All concepts-related text has been removed from the draft.
</p>


<p id="res-1112"><b>Proposed resolution:</b></p>
<ol>
<li>
<p>
Modify the section 22.9.2 <a href="https://wg21.link/template.bitset">[template.bitset]</a> <code>&lt;bitset&gt;</code> synopsis by adding
the following at the end of the synopsis:
</p>
<blockquote><pre>
<ins>
// XX.X.X bitset range access [bitset.range]
template&lt;size_t N&gt; <i>unspecified-1</i> begin(bitset&lt;N&gt;&amp;);
template&lt;size_t N&gt; <i>unspecified-2</i> begin(const bitset&lt;N&gt;&amp;);
template&lt;size_t N&gt; <i>unspecified-1</i> end(bitset&lt;N&gt;&amp;);
template&lt;size_t N&gt; <i>unspecified-2</i> end(const bitset&lt;N&gt;&amp;);
</ins>
</pre></blockquote>
</li>
<li>
<p>
Add a new section <ins>"bitset range access" [bitset.range]</ins>
after the current section 22.9.4 <a href="https://wg21.link/bitset.operators">[bitset.operators]</a> with the following series of
paragraphs:
</p>
<blockquote>
<p>
<ins>
1.  In the <code>begin</code> and <code>end</code> function templates that follow, <i>unspecified-1</i>
is a type that meets the requirements of a mutable random access
iterator (24.3.5.7 <a href="https://wg21.link/random.access.iterators">[random.access.iterators]</a>) whose <code>value_type</code> is <code>bool</code> and
whose reference type is <code>bitset&lt;N&gt;::reference</code>.
<i>unspecified-2</i> is a type that meets the requirements of a constant
random access iterator (24.3.5.7 <a href="https://wg21.link/random.access.iterators">[random.access.iterators]</a>) whose <code>value_type</code>
is <code>bool</code> and whose reference type is <code>bool</code>.
</ins>
</p>
<pre>
<ins>
template&lt;size_t N&gt; <i>unspecified-1</i> begin(bitset&lt;N&gt;&amp;);
template&lt;size_t N&gt; <i>unspecified-2</i> begin(const bitset&lt;N&gt;&amp;);
</ins>
</pre>
<blockquote><p>
<ins>2.  Returns: an iterator referencing the first bit in the bitset.</ins>
</p></blockquote>

<pre><ins>
template&lt;size_t N&gt; <i>unspecified-1</i> end(bitset&lt;N&gt;&amp;);
template&lt;size_t N&gt; <i>unspecified-2</i> end(const bitset&lt;N&gt;&amp;);
</ins></pre>

<blockquote><p>
<ins>3.  Returns: an iterator referencing one past the last bit in the
bitset.</ins>
</p></blockquote>
</blockquote>
</li>
</ol>












</body>
</html>
