<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3523: iota_view::sentinel is not always iota_view's sentinel</title>
<meta property="og:title" content="Issue 3523: iota_view::sentinel is not always iota_view's sentinel">
<meta property="og:description" content="C++ library issue. Status: C++23">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3523.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="3523"><a href="lwg-defects.html#3523">3523</a>. <code>iota_view::<i>sentinel</i></code> is not always <code>iota_view</code>'s sentinel</h3>
<p><b>Section:</b> 25.6.4.2 <a href="https://wg21.link/range.iota.view">[range.iota.view]</a> <b>Status:</b> <a href="lwg-active.html#C++23">C++23</a>
 <b>Submitter:</b> Tim Song <b>Opened:</b> 2021-02-17 <b>Last modified:</b> 2023-11-22</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all other</b> <a href="lwg-index.html#range.iota.view">issues</a> in [range.iota.view].</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>
<a href="https://wg21.link/P1739R4">P1739R4</a> added the following constructor to
<code>iota_view</code>:
</p>
<blockquote><pre>
constexpr iota_view(<i>iterator</i> first, <i>sentinel</i> last) : iota_view(*first, last.<i>bound_</i>) {}
</pre></blockquote>
<p>
However, while <code>iota_view</code>'s iterator type is always <code>iota_view::<i>iterator</i></code>, its sentinel type
is not always <code>iota_view::<i>sentinel</i></code>. First, if <code>Bound</code> is <code>unreachable_sentinel_t</code>, then
the sentinel type is <code>unreachable_sentinel_t</code> too - we don't add an unnecessary level of wrapping
on top. Second, when <code>W</code> and <code>Bound</code> are the same type, <code>iota_view</code> models <code>common_range</code>, and
the sentinel type is the same as the iterator type - that is, <code><i>iterator</i></code>, not <code><i>sentinel</i></code>.
</p>
<p>
Presumably the intent is to use the view's actual sentinel type, rather than always use the
<code><i>sentinel</i></code> type.
</p>

<p><i>[2021-03-12; 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-3523"><b>Proposed resolution:</b></p>
<p>
This wording is relative to <a href="https://wg21.link/n4878">N4878</a>.
</p>

<ol>
<li><p>Edit 25.6.4.2 <a href="https://wg21.link/range.iota.view">[range.iota.view]</a>, as indicated:</p>

<blockquote>
<pre>
namespace std::ranges {
  // [...]

  template&lt;weakly_­incrementable W, semiregular Bound = unreachable_sentinel_t&gt;
    requires <i>weakly-equality-comparable-with</i>&lt;W, Bound&gt; &amp;&amp; semiregular&lt;W&gt;
  class iota_view : public view_interface&lt;iota_view&lt;W, Bound&gt;&gt; {
  private:
    // [range.iota.iterator], class iota_­view​::​iterator
    struct <i>iterator</i>;            // exposition only
    // [range.iota.sentinel], class iota_­view​::​sentinel
    struct <i>sentinel</i>;            // exposition only
    W <i>value_</i> = W();             // exposition only
    Bound <i>bound_</i> = Bound();     // exposition only
  public:
    iota_view() = default;
    constexpr explicit iota_view(W value);
    constexpr iota_view(type_identity_t&lt;W&gt; value,
                        type_identity_t&lt;Bound&gt; bound);
    constexpr iota_view(<i>iterator</i> first, <i><del>sentinel</del><ins>see below</ins></i> last)<ins>;</ins><del>: iota_view(*first, last.<i>bound_</i>) {}</del>

    constexpr <i>iterator</i> begin() const;
    constexpr auto end() const;
    constexpr <i>iterator</i> end() const requires same_­as&lt;W, Bound&gt;;

    constexpr auto size() const requires see below;
  };

  template&lt;class W, class Bound&gt;
      requires (!<i>is-integer-like</i>&lt;W&gt; || !<i>is-integer-like</i>&lt;Bound&gt; ||
              (<i>is-signed-integer-like</i>&lt;W&gt; == <i>is-signed-integer-like</i>&lt;Bound&gt;))
      iota_view(W, Bound) -&gt; iota_view&lt;W, Bound&gt;;
}
</pre>
<p>[...]</p>
<pre>
constexpr iota_view(type_identity_t&lt;W&gt; value, type_identity_t&lt;Bound&gt; bound);
</pre>
<blockquote>
<p>-8- <i>Preconditions</i>: <code>Bound</code> denotes <code>unreachable_­sentinel_­t</code> or <code>bound</code> is reachable
from <code>value</code>. When <code>W</code> and <code>Bound</code> model <code>totally_­ordered_­with</code>, then <code>bool(value &lt;= bound)</code> is true.</p>
<p>-9- <i>Effects</i>: Initializes <code><i>value_</i></code>­ with <code>value</code> and <code><i>bound_</i></code> with <code>bound</code>.</p>
</blockquote>
<pre>
<ins>constexpr iota_view(<i>iterator</i> first, <i>see below</i> last);</ins>
</pre>
<blockquote>
<p><ins>-?- <i>Effects</i>: Equivalent to:</ins></p>
<ol style="list-style-type: none">
<li><p><ins>(?.1) &mdash; If <code>same_as&lt;W, Bound&gt;</code> is <code>true</code>, <code>iota_view(first.<i>value_</i>, last.<i>value_</i>)</code>.</ins></p></li>
<li><p><ins>(?.2) &mdash; Otherwise, if <code>Bound</code> denotes <code>unreachable_sentinel_t</code>, <code>iota_view(first.<i>value_</i>, last)</code>.</ins></p></li>
<li><p><ins>(?.3) &mdash; Otherwise, <code>iota_view(first.<i>value_</i>, last.<i>bound_</i>)</code>.</ins></p></li>
</ol>
<p><ins>-?- <i>Remarks</i>: The type of <code>last</code> is:</ins></p>
<ol style="list-style-type: none">
<li><p><ins>(?.1) &mdash; If <code>same_as&lt;W, Bound&gt;</code> is <code>true</code>, <code><i>iterator</i></code>.</ins></p></li>
<li><p><ins>(?.2) &mdash; Otherwise, if <code>Bound</code> denotes <code>unreachable_sentinel_t</code>, <code>Bound</code>.</ins></p></li>
<li><p><ins>(?.3) &mdash; Otherwise, <code><i>sentinel</i></code>.</ins></p></li>
</ol>
</blockquote>
</blockquote>
</li>
</ol>





</body>
</html>
