<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3623: Uses of std::reverse_iterator with containers should not require manually including &lt;iterator&gt;</title>
<meta property="og:title" content="Issue 3623: Uses of std::reverse_iterator with containers should not require manually including &lt;iterator&gt;">
<meta property="og:description" content="C++ library issue. Status: New">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3623.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="3623"><a href="lwg-active.html#3623">3623</a>. Uses of <code>std::reverse_iterator</code> with containers should not require manually including <code>&lt;iterator&gt;</code></h3>
<p><b>Section:</b> 24.5.1.1 <a href="https://wg21.link/reverse.iterators.general">[reverse.iterators.general]</a> <b>Status:</b> <a href="lwg-active.html#New">New</a>
 <b>Submitter:</b> Jiang An <b>Opened:</b> 2021-10-23 <b>Last modified:</b> 2022-01-29</p>
<p><b>Priority: </b>3
</p>
<p><b>View all issues with</b> <a href="lwg-status.html#New">New</a> status.</p>
<p><b>Discussion:</b></p>
<p>
Currently it is unspecified whether the definitions of <code>std::reverse_iterator</code> and its related 
operators are available in <code>&lt;vector&gt;</code>, <code>&lt;array&gt;</code>, etc. So, it's unspecified 
now whether the following program is well-formed because it's unspecified whether the equality operator 
is available:
</p>
<blockquote><pre>
#include &lt;vector&gt;

int main()
{
  auto v = std::vector&lt;int&gt;(42);
  for (auto it = v.rbegin(); it != v.rend(); ++it);
  for (auto it = std::rbegin(v); it != std::rend(v); ++it);
}</pre></blockquote>
<p>
 Such underspecification also leaves the guarantee that <code>std::rbegin</code>, <code>std::rend</code>, 
 <code>std::crbegin</code>, and <code>std::crend</code> are available in some other headers seems not so meaningful. 
 In order to guarantee these function templates can be used meaningfully with containers, users are still 
 required to include <code>&lt;iterator&gt;</code> manually.
<p/>
I think the standard should guarantee that wherever the member <code>rbegin</code> (that returns <code>std::reverse_iterator</code>) 
or <code>std::rbegin</code> is provided, the definitions of <code>std::reverse_iterator</code> and its related operators 
are also provided. This strategy is already implemented by libc++, libstdc++, and MSVC STL, and thus I believe we 
should standardize it to reduce uncertainty for users.
<p/>
Note that the situation for <code>std::reverse_iterator</code> is different from LWG <a href="lwg-closed.html#1361" title="Does use of std::size_t in a header imply that typedef name is available to users? (Status: NAD)">1361</a><sup><a href="https://cplusplus.github.io/LWG/issue1361" title="Latest snapshot">(i)</a></sup>, because every 
operation on <code>std::size_t</code> is still valid when the typedef-name itself is absent, but <code>==</code> and 
<code>!=</code> on <code>std::reverse_iterator</code> fail if the corresponding declarations are unavailable.
</p>

<p><i>[2022-01-29; Reflector poll]</i></p>

<p>
Set priority to 3 after reflector poll.
</p>



<p id="res-3623"><b>Proposed resolution:</b></p>
<p>
This wording is relative to <a href="https://wg21.link/n4901">N4901</a>.
</p>

<ol>
<li><p>Modify 24.5.1.1 <a href="https://wg21.link/reverse.iterators.general">[reverse.iterators.general]</a> as indicated:</p>

<blockquote>
<p>
-1- Class template <code>reverse_iterator</code> is an iterator adaptor that iterates from the end of the sequence defined
by its underlying iterator to the beginning of that sequence.
<p/>
<ins>-?- In addition to being available via inclusion of the <code>&lt;iterator&gt;</code> header, class template 
<code>reverse_iterator</code> and function templates in 24.5.1.8 <a href="https://wg21.link/reverse.iter.cmp">[reverse.iter.cmp]</a> and 24.5.1.9 <a href="https://wg21.link/reverse.iter.nonmember">[reverse.iter.nonmember]</a> 
are available when any of the following headers are included: <code>&lt;array&gt;</code>  (23.3.2 <a href="https://wg21.link/array.syn">[array.syn]</a>), 
<code>&lt;deque&gt;</code>  (23.3.4 <a href="https://wg21.link/deque.syn">[deque.syn]</a>), <code>&lt;forward_list&gt;</code> (23.3.6 <a href="https://wg21.link/forward.list.syn">[forward.list.syn]</a>), 
<code>&lt;list&gt;</code> (23.3.10 <a href="https://wg21.link/list.syn">[list.syn]</a>), <code>&lt;map&gt;</code> (23.4.2 <a href="https://wg21.link/associative.map.syn">[associative.map.syn]</a>), 
<code>&lt;regex&gt;</code> (28.6.3 <a href="https://wg21.link/re.syn">[re.syn]</a>), <code>&lt;set&gt;</code> (23.4.5 <a href="https://wg21.link/associative.set.syn">[associative.set.syn]</a>), 
<code>&lt;span&gt;</code> (23.7.2.1 <a href="https://wg21.link/span.syn">[span.syn]</a>), <code>&lt;stacktrace&gt;</code> (19.6.2 <a href="https://wg21.link/stacktrace.syn">[stacktrace.syn]</a>), 
<code>&lt;string&gt;</code> (27.4.2 <a href="https://wg21.link/string.syn">[string.syn]</a>), <code>&lt;string_view&gt;</code> (27.3.2 <a href="https://wg21.link/string.view.synop">[string.view.synop]</a>), 
<code>&lt;unordered_map&gt;</code> (23.5.2 <a href="https://wg21.link/unord.map.syn">[unord.map.syn]</a>), <code>&lt;unordered_set&gt;</code> (23.5.5 <a href="https://wg21.link/unord.set.syn">[unord.set.syn]</a>), 
and <code>&lt;vector&gt;</code> (23.3.12 <a href="https://wg21.link/vector.syn">[vector.syn]</a>).</ins>
</p>
</blockquote>
</li>
</ol>





</body>
</html>
