<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3449: take_view and take_while_view's sentinel&lt;false&gt; not comparable with their const iterator</title>
<meta property="og:title" content="Issue 3449: take_view and take_while_view's sentinel&lt;false&gt; not comparable with their const iterator">
<meta property="og:description" content="C++ library issue. Status: C++23">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3449.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="3449"><a href="lwg-defects.html#3449">3449</a>. <code>take_view</code> and <code>take_while_view</code>'s <code><i>sentinel</i>&lt;false&gt;</code> not comparable with their const iterator</h3>
<p><b>Section:</b> 25.7.10.3 <a href="https://wg21.link/range.take.sentinel">[range.take.sentinel]</a>, 25.7.11.3 <a href="https://wg21.link/range.take.while.sentinel">[range.take.while.sentinel]</a> <b>Status:</b> <a href="lwg-active.html#C++23">C++23</a>
 <b>Submitter:</b> Tim Song <b>Opened:</b> 2020-06-06 <b>Last modified:</b> 2023-11-22</p>
<p><b>Priority: </b>1
</p>
<p><b>View all other</b> <a href="lwg-index.html#range.take.sentinel">issues</a> in [range.take.sentinel].</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>
During reflector discussion it was noted that the issue observed in
LWG <a href="lwg-defects.html#3448" title="transform_view's sentinel&lt;false&gt; not comparable with iterator&lt;true&gt; (Status: C++23)">3448</a><sup><a href="https://cplusplus.github.io/LWG/issue3448" title="Latest snapshot">(i)</a></sup> applies to <code>take_view::<i>sentinel</i></code>
and <code>take_while_view::<i>sentinel</i></code> as well.
</p>

<p><i>[2020-06-15 Tim corrects a typo in the PR]</i></p>


<p><i>[2020-10-02; Priority set to 1 in telecon]</i></p>

<p>
Should be considered together with <a href="lwg-defects.html#3406" title="elements_view::begin() and elements_view::end() have incompatible
constraints (Status: C++23)">3406</a><sup><a href="https://cplusplus.github.io/LWG/issue3406" title="Latest snapshot">(i)</a></sup> and <a href="lwg-defects.html#3448" title="transform_view's sentinel&lt;false&gt; not comparable with iterator&lt;true&gt; (Status: C++23)">3448</a><sup><a href="https://cplusplus.github.io/LWG/issue3448" title="Latest snapshot">(i)</a></sup>.
</p>

<p><i>[2020-10-02; Status to Tentatively Ready after five positive votes on the reflector]</i></p>


<p><i>[2020-11-09 Approved In November virtual meeting. Status changed: Tentatively Ready &rarr; WP.]</i></p>



<p id="res-3449"><b>Proposed resolution:</b></p>
<p>This wording is relative to <a href="https://wg21.link/n4861">N4861</a>. It assumes
the <code><i>maybe-const</i></code> helper introduced by the P/R of LWG <a href="lwg-defects.html#3448" title="transform_view's sentinel&lt;false&gt; not comparable with iterator&lt;true&gt; (Status: C++23)">3448</a><sup><a href="https://cplusplus.github.io/LWG/issue3448" title="Latest snapshot">(i)</a></sup>.</p>

<ol>
<li><p>Modify 25.7.10.3 <a href="https://wg21.link/range.take.sentinel">[range.take.sentinel]</a> as indicated:</p>

<blockquote class="note"> 
<p>
[<i>Drafting note</i>: Unlike LWG <a href="lwg-defects.html#3448" title="transform_view's sentinel&lt;false&gt; not comparable with iterator&lt;true&gt; (Status: C++23)">3448</a><sup><a href="https://cplusplus.github.io/LWG/issue3448" title="Latest snapshot">(i)</a></sup>, these operators can't be easily templatized,
so the approach taken here is to add an overload for the opposite constness instead.
However, because <code>const V</code> may not even be a range (and therefore
<code>iterator_t&lt;const V&gt;</code> may not be well-formed), we need to defer
instantiating the signature of the new overload until the point of use. ]
</p>
</blockquote>
<blockquote>
<blockquote>
<pre>
namespace std::ranges {
  template&lt;view V&gt;
  template&lt;bool Const&gt;
  class take_view&lt;V&gt;::<i>sentinel</i> {
  private:
    using <i>Base</i> = conditional_t&lt;Const, const V, V&gt;;  // exposition only
    <ins>template&lt;bool OtherConst&gt;</ins>
    using <i>CI</i> = counted_iterator&lt;iterator_t&lt;<del><i>Base</i></del><ins><i>maybe-const</i>&lt;OtherConst, V&gt;</ins>&gt;&gt;;  // exposition only

    [&hellip;]

    constexpr sentinel_t&lt;<i>Base</i>&gt; base() const;

    friend constexpr bool operator==(const <i>CI</i><ins>&lt;Const&gt;</ins>&amp; y, const <i>sentinel</i>&amp; x);
    <ins>
    template&lt;bool OtherConst = !Const&gt;
        requires sentinel_for&lt;sentinel_t&lt;<i>Base</i>&gt;, iterator_t&lt;<i>maybe-const</i>&lt;OtherConst, V&gt;&gt;&gt;
    friend constexpr bool operator==(const <i>CI</i>&lt;OtherConst&gt;&amp; y, const <i>sentinel</i>&amp; x);
    </ins>
  };
}
</pre>
</blockquote>
[&hellip;]
<pre>
friend constexpr bool operator==(const <i>CI</i><ins>&lt;Const&gt;</ins>&amp; y, const <i>sentinel</i>&amp; x);
<ins>
template&lt;bool OtherConst = !Const&gt;
    requires sentinel_for&lt;sentinel_t&lt;<i>Base</i>&gt;, iterator_t&lt;<i>maybe-const</i>&lt;OtherConst, V&gt;&gt;&gt;
friend constexpr bool operator==(const <i>CI</i>&lt;OtherConst&gt;&amp; y, const <i>sentinel</i>&amp; x);
</ins>
</pre>
<blockquote>
<p>
-4- <i>Effects:</i> Equivalent to: <code>return y.count() == 0 || y.base() == x.<i>end_</i>;</code>
</p>
</blockquote>
</blockquote>
</li>
<li><p>Modify 25.7.11.3 <a href="https://wg21.link/range.take.while.sentinel">[range.take.while.sentinel]</a> as indicated:</p>
<blockquote>
<blockquote>
<pre>
namespace std::ranges {
    template&lt;view V, class Pred&gt;
    requires input_range&lt;V&gt; &amp;&amp; is_object_v&lt;Pred&gt; &amp;&amp;
                indirect_unary_predicate&lt;const Pred, iterator_t&lt;V&gt;&gt;
    template&lt;bool Const&gt;
    class take_while_view&lt;V&gt;::<i>sentinel</i> {
      [&hellip;]

      constexpr sentinel_t&lt;<i>Base</i>&gt; base() const { return <i>end_</i>; }

      friend constexpr bool operator==(const iterator_t&lt;<i>Base</i>&gt;&amp; x, const <i>sentinel</i>&amp; y);
      <ins>
      template&lt;bool OtherConst = !Const&gt;
          requires sentinel_for&lt;sentinel_t&lt;<i>Base</i>&gt;, iterator_t&lt;<i>maybe-const</i>&lt;OtherConst, V&gt;&gt;&gt;
      friend constexpr bool operator==(const iterator_t&lt;<i>maybe-const</i>&lt;OtherConst, V&gt;&gt;&amp; x, const <i>sentinel</i>&amp; y);
      </ins>
    };
}
</pre>
</blockquote>
[&hellip;]
<pre>
friend constexpr bool operator==(const iterator_t&lt;<i>Base</i>&gt;&amp; x, const <i>sentinel</i>&amp; y);
<ins>
template&lt;bool OtherConst = !Const&gt;
    requires sentinel_for&lt;sentinel_t&lt;<i>Base</i>&gt;, iterator_t&lt;<i>maybe-const</i>&lt;OtherConst, V&gt;&gt;&gt;
friend constexpr bool operator==(const iterator_t&lt;<i>maybe-const</i>&lt;OtherConst, V&gt;&gt;&amp; x, const <i>sentinel</i>&amp; y);
</ins>
</pre>
<blockquote>
<p>
-3- <i>Effects:</i> Equivalent to: <code>return y.<i>end_</i> == x || !invoke(*y.<i>pred_</i>, *x);</code>
</p>
</blockquote>
</blockquote>
</li>
</ol>




</body>
</html>
