<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 4001: iota_view should provide empty</title>
<meta property="og:title" content="Issue 4001: iota_view should provide empty">
<meta property="og:description" content="C++ library issue. Status: WP">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue4001.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#WP">WP</a> status.</em></p>
<h3 id="4001"><a href="lwg-defects.html#4001">4001</a>. <code>iota_view</code> should provide <code>empty</code></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#WP">WP</a>
 <b>Submitter:</b> Hewill Kang <b>Opened:</b> 2023-10-27 <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#WP">WP</a> status.</p>
<p><b>Discussion:</b></p>
<p>
When <code>iota_view</code>'s template parameter is not an integer type and does not model <code><i>advanceable</i></code>, 
its <code>size</code> member will not be provided as constraints are not satisfied.
<p/>
If the type further fails to model the <code>incrementable</code>, this results in its <code>view_interface</code> base being 
unable to synthesize a valid <code>empty</code> member as <code>iota_view</code> will just be an <code>input_range</code> 
(<a href="https://godbolt.org/z/hG9GWvv97">demo</a>):
</p>
<blockquote><pre>
#include &lt;ranges&gt;
#include &lt;vector&gt;
#include &lt;iostream&gt;

int main() {
  std::vector&lt;int&gt; v;
  auto it = std::back_inserter(v);
  auto s = std::ranges::subrange(it, std::unreachable_sentinel);
  auto r = std::views::iota(it);
  std::cout &lt;&lt; s.empty() &lt;&lt; "\n"; // 0
  std::cout &lt;&lt; r.empty() &lt;&lt; "\n"; // <span style="color:red;font-weight:bolder">ill-formed</span>
}
</pre></blockquote>
<p>
This seems to be an oversight. I don't see a reason why <code>iota_view</code> doesn't provide <code>empty</code> 
as it does store the start and end like <code>subrange</code>, in which case it's easy to tell if it's empty 
just by comparing the two.
</p>

<p><i>[2023-11-02; Reflector poll]</i></p>

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

<p><i>[2023-11-11 Approved at November 2023 meeting in Kona. Status changed: Voting &rarr; WP.]</i></p>



<p id="res-4001"><b>Proposed resolution:</b></p>
<p>
This wording is relative to <a href="https://wg21.link/N4964" title=" Working Draft, Programming Languages — C++">N4964</a>.
</p>

<ol>

<li><p>Modify 25.6.4.2 <a href="https://wg21.link/range.iota.view">[range.iota.view]</a>, class template <code>iota_view</code> synopsis, as indicated:</p>

<blockquote>
<blockquote><pre>
namespace std::ranges {
  [&hellip;]
  template&lt;weakly_incrementable W, semiregular Bound = unreachable_sentinel_t&gt;
    requires <i>weakly-equality-comparable-with</i>&lt;W, Bound&gt; &amp;&amp; copyable&lt;W&gt;
  class iota_view : public view_interface&lt;iota_view&lt;W, Bound&gt;&gt; {
  private:
    [&hellip;]
    W <i>value_</i> = W();                     // <i>exposition only</i>
    Bound <i>bound_</i> = Bound();             // <i>exposition only</i>
  public:
    [&hellip;]
    constexpr <i>iterator</i> begin() const;
    constexpr auto end() const;
    constexpr <i>iterator</i> end() const requires same_as&lt;W, Bound&gt;;

    <ins>constexpr bool empty() const;</ins>
    constexpr auto size() const requires <i>see below</i>;
  };
  [&hellip;]
}
</pre></blockquote>
<p>
[&hellip;]
</p>
<pre>
constexpr <i>iterator</i> end() const requires same_as&lt;W, Bound&gt;;
</pre>
<blockquote>
<p>
-14- <i>Effects</i>: Equivalent to: <code>return <i>iterator</i>{<i>bound_</i>};</code> 
</p>
</blockquote>
<pre>
<ins>constexpr bool empty() const;</ins>
</pre>
<blockquote>
<p>
<ins>-?- <i>Effects</i>: Equivalent to: <code>return <i>value_</i> == <i>bound_</i>;</code></ins>
<p/>
[&hellip;]
</p>
</blockquote>
</blockquote>

</li>

</ol>





</body>
</html>
