<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 1422: vector&lt;bool&gt; iterators are not random access</title>
<meta property="og:title" content="Issue 1422: vector&lt;bool&gt; iterators are not random access">
<meta property="og:description" content="C++ library issue. Status: Open">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue1422.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#Open">Open</a> status.</em></p>
<h3 id="1422"><a href="lwg-active.html#1422">1422</a>. <code>vector&lt;bool&gt;</code> iterators are not random access</h3>
<p><b>Section:</b> 23.3.14 <a href="https://wg21.link/vector.bool">[vector.bool]</a> <b>Status:</b> <a href="lwg-active.html#Open">Open</a>
 <b>Submitter:</b> BSI <b>Opened:</b> 2010-08-25 <b>Last modified:</b> 2020-09-06</p>
<p><b>Priority: </b>3
</p>
<p><b>View other</b> <a href="lwg-index-open.html#vector.bool">active issues</a> in [vector.bool].</p>
<p><b>View all other</b> <a href="lwg-index.html#vector.bool">issues</a> in [vector.bool].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#Open">Open</a> status.</p>
<p><b>Discussion:</b></p>
<p><b>Addresses GB-118</b></p>
<p>
<code>vector&lt;bool&gt;</code> iterators are not random access iterators
because their reference type is a special class, and not
<code>bool &amp;</code>. All standard libary operations taking iterators
should treat this iterator as if it was a random access iterator, rather
than a simple input iterator.
</p>

<p><i>[
Resolution proposed in ballot comment
]</i></p>

<p>
Either revise the iterator requirements to support proxy iterators
(restoring functionality that was lost when the Concept facility was
removed) or add an extra paragraph to the <code>vector&lt;bool&gt;</code>
specification requiring the library to treat <code>vector&lt;bool&gt;</code>
iterators as-if they were random access iterators, despite having the wrong
reference type.
</p>

<p><i>[
Rapperswil Review
]</i></p>

<p>
The consensus at Rapperswil is that it is too late for full support for
proxy iterators, but requiring the library to respect <code>vector&lt;bool&gt;</code>
iterators as-if they were random access would be preferable to flagging
this container as deliberately incompatible with standard library algorithms.
</p>
<p>
Alisdair to write the note, which may become normative <i>Remark</i> depending
on the preferences of the project editor.
</p>

<p><i>[
Post-Rapperswil Alisdair provides wording
]</i></p>

<p>
Initial wording is supplied, deliberately using <i>Note</i> in preference to
<i>Remark</i> although the author notes his preference for <i>Remark</i>.  The
issue of whether <code>iterator_traits&lt;vector&lt;bool&gt;&gt;::iterator_category</code>
is permitted to report <code>random_access_iterator_tag</code> or must report 
<code>input_iterator_tag</code> is not addressed.
</p>

<p><i>[
Old Proposed Resolution:
]</i></p>

<blockquote>
<p>
Insert a new paragraph into 23.3.14 <a href="https://wg21.link/vector.bool">[vector.bool]</a> between p4 and p5:
</p>
<blockquote><p>
[<i>Note</i> All functions in the library that take a pair of iterators to
denote a range shall treat <code>vector&lt;bool&gt;</code> iterators as-if they were
random access iterators, even though the <code>reference</code> type is not a
true reference.<i>-- end note</i>]
</p></blockquote>
</blockquote>

<p><i>[
2010-11 Batavia:
]</i></p>

<blockquote><p>
Closed as NAD Future, because the current iterator categories cannot correctly describe
<code>vector&lt;bool&gt;::iterator</code>. But saying that they are Random Access Iterators
is also incorrect, because it is not too hard to create a corresponding test that fails.
We should deal with the more general proxy iterator problem in the future, and see no
benefit to take a partial workaround specific to <code>vector&lt;bool&gt;</code> now.
</p></blockquote>

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

<p>D0022 Proxy Iterators for the Ranges Extensions -
as much a fix as we’re going to get for vector&lt;bool&gt;.</p>

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

<p><a href="https://wg21.link/P0022">P0022</a> is exploring a resolution. 
We consider this to be fairly important issue</p>
<p>Move to Open, set priority to 3</p>


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


<p><b>Rationale:</b></p>
<p>
No consensus to make this change at this time.
</p>





</body>
</html>
