<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3533: Make base() const &amp; consistent across iterator wrappers that supports input_iterators</title>
<meta property="og:title" content="Issue 3533: Make base() const &amp; consistent across iterator wrappers that supports input_iterators">
<meta property="og:description" content="C++ library issue. Status: C++23">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3533.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#C++23">C++23</a> status.</em></p>
<h3 id="3533"><a href="lwg-defects.html#3533">3533</a>. Make <code>base() const &amp;</code> consistent across iterator wrappers that supports <code>input_iterator</code>s</h3>
<p><b>Section:</b> 25.7.8.3 <a href="https://wg21.link/range.filter.iterator">[range.filter.iterator]</a>, 25.7.9.3 <a href="https://wg21.link/range.transform.iterator">[range.transform.iterator]</a>, 25.7.23.3 <a href="https://wg21.link/range.elements.iterator">[range.elements.iterator]</a> <b>Status:</b> <a href="lwg-active.html#C++23">C++23</a>
 <b>Submitter:</b> Tomasz Kami&nacute;ski <b>Opened:</b> 2021-03-14 <b>Last modified:</b> 2023-11-22</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++23">C++23</a> status.</p>
<p><b>Discussion:</b></p>
<p>
The resolution of LWG issue <a href="lwg-defects.html#3391" title="Problems with counted_iterator/move_iterator::base() const &amp; (Status: C++23)">3391</a><sup><a href="https://cplusplus.github.io/LWG/issue3391" title="Latest snapshot">(i)</a></sup> changed the <code>base()</code> function for the 
<code>counted_iterator</code>/<code>move_iterator</code> to return <code>const &amp;</code>, because the previous 
specification prevented non-mutating uses of the base iterator (comparing against sentinel) and made 
<code>take_view</code> unimplementable. However, this change was not applied for all other iterators wrappers, 
that may wrap move-only input iterators. As consequence, we end-up with inconsistency where a user can 
perform the following operations on some adapters, but not on others (e. g. <code>take_view</code> uses 
<code>counted_iterator</code> so it supports them).
</p>
<ol style="list-style-type:upper-alpha">
<li><p>read the original value of the base iterator, by calling <code>operator*</code></p></li>
<li><p>find position of an element in the underlying iterator, when sentinel is sized by calling <code>operator-</code> 
(e.g. all input iterators wrapped into <code>counted_iterator</code>).</p></li>
</ol>
<p>
To fix above, the proposed wording below proposes to modify the signature of <code>iterator::base() const &amp;</code> 
member function for all iterators adapters that support input iterator. These include:
</p>
<ul>
<li><p><code>filter_view::<i>iterator</i></code> (uses case B)</p></li>
<li><p><code>transform_view::<i>iterator</i></code> (uses case A)</p></li>
<li><p><code>elements_view::<i>iterator</i></code> (uses case B)</p></li>
<li><p><code>lazy_split_view&lt;V, Pattern&gt;::<i>inner-iterator</i></code> (uses case B) if 
<a href="https://wg21.link/p2210">P2210</a> is accepted</p></li>
</ul>
<p>
Note: <code>common_iterator</code> does not expose the <code>base()</code> function (because it can either point to 
iterator or sentinel), so changes to above are not proposed. However, both (A) and (B) use cases are supported.
</p>

<p><i>[2021-04-20; Reflector poll]</i></p>

<p>
Set status to Tentatively Ready after five votes in favour during reflector poll.
</p>

<p><i>[2021-06-07 Approved at June 2021 virtual plenary. Status changed: Voting &rarr; WP.]</i></p>



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

<blockquote class="note">
<p>
If <a href="https://wg21.link/p2210">P2210</a> would become accepted, the corresponding subclause 
[range.lazy.split.inner] (?) for <code>lazy_split_view::<i>inner-iterator</i></code> would require a similar change.
</p>
</blockquote>

<ol>
<li><p>Modify 25.7.8.3 <a href="https://wg21.link/range.filter.iterator">[range.filter.iterator]</a> as indicated:</p>

<blockquote>
<blockquote>
<pre>
[&hellip;]
constexpr <ins>const</ins> iterator_t&lt;V&gt;<ins>&amp;</ins> base() const &amp;
  <del>requires copyable&lt;iterator_t&lt;V&gt;&gt;</del>;
[&hellip;]
</pre>
</blockquote>
</blockquote>
[&hellip;]
<blockquote>
<pre>
constexpr <ins>const</ins> iterator_t&lt;V&gt;<ins>&amp;</ins> base() const &amp;
  <del>requires copyable&lt;iterator_t&lt;V&gt;&gt;</del>;
</pre>
<blockquote>
<p>
-5- <i>Effects:</i> Equivalent to: <code>return <i>current_</i>;</code>
</p>
</blockquote>
</blockquote>
</li>

<li><p>Modify 25.7.9.3 <a href="https://wg21.link/range.transform.iterator">[range.transform.iterator]</a> as indicated:</p>

<blockquote>
<blockquote>
<pre>
[&hellip;]
constexpr <ins>const</ins> iterator_t&lt;<i>Base</i>&gt;<ins>&amp;</ins> base() const &amp;
  <del>requires copyable&lt;iterator_t&lt;<i>Base</i>&gt;&gt;</del>;
[&hellip;]
</pre>
</blockquote>
</blockquote>
[&hellip;]
<blockquote>
<pre>
constexpr <ins>const</ins> iterator_t&lt;<i>Base</i>&gt;<ins>&amp;</ins> base() const &amp;
  <del>requires copyable&lt;iterator_t&lt;<i>Base</i>&gt;&gt;</del>;
</pre>
<blockquote>
<p>
-5- <i>Effects:</i> Equivalent to: <code>return <i>current_</i>;</code>
</p>
</blockquote>
</blockquote>
</li>

<li><p>Modify 25.7.23.3 <a href="https://wg21.link/range.elements.iterator">[range.elements.iterator]</a> as indicated:</p>

<blockquote>
<blockquote>
<pre>
[&hellip;]
constexpr <ins>const</ins> iterator_t&lt;<i>Base</i>&gt;<ins>&amp;</ins> base() const &amp;
  <del>requires copyable&lt;iterator_t&lt;<i>Base</i>&gt;&gt;</del>;
[&hellip;]
</pre>
</blockquote>
</blockquote>
[&hellip;]
<blockquote>
<pre>
constexpr <ins>const</ins> iterator_t&lt;<i>Base</i>&gt;<ins>&amp;</ins> base() const &amp;
  <del>requires copyable&lt;iterator_t&lt;<i>Base</i>&gt;&gt;</del>;
</pre>
<blockquote>
<p>
-3- <i>Effects:</i> Equivalent to: <code>return <i>current_</i>;</code>
</p>
</blockquote>
</blockquote>
</li>

</ol>






</body>
</html>
