<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3363: drop_while_view should opt-out of sized_range</title>
<meta property="og:title" content="Issue 3363: drop_while_view should opt-out of sized_range">
<meta property="og:description" content="C++ library issue. Status: C++20">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3363.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++20">C++20</a> status.</em></p>
<h3 id="3363"><a href="lwg-defects.html#3363">3363</a>. <code>drop_while_view</code> should opt-out of <code>sized_range</code></h3>
<p><b>Section:</b> 25.7.13.2 <a href="https://wg21.link/range.drop.while.view">[range.drop.while.view]</a> <b>Status:</b> <a href="lwg-active.html#C++20">C++20</a>
 <b>Submitter:</b> Johel Ernesto Guerrero Pe&ntilde;a <b>Opened:</b> 2020-01-07 <b>Last modified:</b> 2021-02-25</p>
<p><b>Priority: </b>1
</p>
<p><b>View all other</b> <a href="lwg-index.html#range.drop.while.view">issues</a> in [range.drop.while.view].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++20">C++20</a> status.</p>
<p><b>Discussion:</b></p>
<p>If <code>drop_while_view</code>'s <code>iterator_t</code> and <code>sentinel_t</code>
model <code>forward_iterator</code> and <code>sized_sentinel_for</code>, it will 
incorrectly satisfy <code>sized_range</code> thanks to the size member function
inherited from <code>view_interface</code>.</p>

<p>Because it has to compute its <code>begin()</code>, it can never model 
<code>sized_range</code> due to not meeting its non-amortized O(1) requirement.</p>

<p><i>[2020-01-16 Priority set to 1 after discussion on the reflector.]</i></p>


<p><i>[2020-02-10; Prague 2020; Casey comments and provides alternative wording]</i></p>

<p>
The fundamental issue here is that both <code>ranges::size</code> and <code>view_interface::size</code> 
(it should be unsurprising that many of the "default" implementations of member <code>meow</code> in 
<code>view_interface</code> look just like fallback cases of the <code>ranges::meow</code> CPO) have 
a case that returns the difference of <code>ranges::end</code> and <code>ranges::begin</code>. If 
<code>begin</code> and <code>end</code> are amortized* O(1) but not "true" O(1), then the resulting 
<code>size</code> operation is amortized O(1) and not "true" O(1) as required by the 
<code>sized_range</code> concept. I don't believe we can or should fix this on a case by case basis,
but we should instead relax the complexity requirement for <code>sized_range</code> to be 
handwavy-amortized O(1).
</p>

<p><strong>Previous resolution [SUPERSEDED]:</strong></p>
<blockquote class="note">
<p>This wording is relative to <a href="https://wg21.link/N4849">N4849</a>.</p>

<ol>
<li><p>Add the following specialization to 25.2 <a href="https://wg21.link/ranges.syn">[ranges.syn]</a>:</p>

<blockquote>
<pre>
// [drop.while.view], drop while view
  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;
    class drop_while_view;

<ins>
  template&lt;view V, class Pred&gt;
    inline constexpr bool disable_sized_range&lt;drop_while_view&lt;V, Pred&gt;&gt; = true;
</ins>

  namespace views { inline constexpr unspecified drop_while = unspecified; }
</pre>
</blockquote>

</li>
</ol>
</blockquote>

<p><i>[2020-02 Moved to Immediate on Tuesday in Prague.]</i></p>



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

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

<blockquote>
<p>
-2- Given an lvalue <code>t</code> of type <code>remove_reference_t&lt;T&gt;</code>, <code>T</code> models 
<code>sized_range</code> only if
</p>
<ol style="list-style-type: none"> 
<li><p>(2.1) &mdash; <code>ranges::size(t)</code> is <ins>amortized</ins> &#x1d4aa;(<code>1</code>), does not modify <code>t</code>, 
and is equal to <code>ranges::distance(t)</code>, and</p></li>
<li><p>[&hellip;]</p></li>
</ol>
<p>
<del>-3- [<i>Note:</i> The complexity requirement for the evaluation of <code>ranges::size</code> is non-amortized, unlike the
case for the complexity of the evaluations of <code>ranges::begin</code> and <code>ranges::end</code> in the <code>range</code> concept.
&mdash; <i>end note</i>]</del>
</p>
</blockquote>

</li>
</ol>





</body>
</html>
