<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 4062: ranges::empty has no semantic requirements for forward_ranges</title>
<meta property="og:title" content="Issue 4062: ranges::empty has no semantic requirements for forward_ranges">
<meta property="og:description" content="C++ library issue. Status: New">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue4062.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#New">New</a> status.</em></p>
<h3 id="4062"><a href="lwg-active.html#4062">4062</a>. <code>ranges::empty</code> has no semantic requirements for <code>forward_range</code>s</h3>
<p><b>Section:</b> 25.3.13 <a href="https://wg21.link/range.prim.empty">[range.prim.empty]</a> <b>Status:</b> <a href="lwg-active.html#New">New</a>
 <b>Submitter:</b> Hewill Kang <b>Opened:</b> 2024-03-30 <b>Last modified:</b> 2024-03-30</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all issues with</b> <a href="lwg-status.html#New">New</a> status.</p>
<p><b>Discussion:</b></p>
<p>
This is a small part of issues raised by already-closed <a href="https://wg21.link/P3156" title=" empty_checkable_range">P3156</a>.
<p/>
Currently, <code>ranges::empty</code> (25.3.13 <a href="https://wg21.link/range.prim.empty">[range.prim.empty]</a>) is always a valid expression when applied
to <code>forward_range</code>s, because even if it does not have <code>.empty()</code> or <code>.size()</code> we can always
check whether it is empty by comparing its <code>begin()</code> and <code>end()</code>, which is reflected in the 
standard preference to use it to check whether a certain <code>forward_range</code> is empty,
such as in the <i>Effects</i> of <code>split_view::<i>find-next</i>()</code> (25.7.17.2 <a href="https://wg21.link/range.split.view">[range.split.view]</a>) 
and <code>cartesian_product_view::end()</code> (25.7.33.2 <a href="https://wg21.link/range.cartesian.view">[range.cartesian.view]</a>).
<p/>
In addition, MSVC-STL also uses <code>ranges::empty</code> in the <a
href="https://github.com/microsoft/STL/blob/8e2d724cc1072b4052b14d8c5f81a830b8f1d8cb/stl/inc/algorithm#L1455">implementation</a>
of <code>ranges::contains_subrange</code> for the check.
<p/>
However, unlike <code>ranges::size</code>, which has a <code>sized_range</code> concept to ensure semantics,
<code>ranges::empty</code> has no corresponding one. This makes it lack of time complexity guarantees and semantics 
for the meaning of the returned value when using the bullets (2.2) and (2.3) of 25.3.13 <a href="https://wg21.link/range.prim.empty">[range.prim.empty]</a>
to check emptiness.
<p/>
Perhaps we need to add semantic requirements for <code>ranges::empty</code>, but this seems
inconsistent with the current wording as no other CPOs have.
<p/>
Alternatively, maybe we could move bullets targeting <code>forward_range</code>s to the very beginning so that
<code>ranges::empty</code> always has correct semantics with <code>bool(ranges::begin(t) == ranges::end(t))</code> when
applied to <code>forward_range</code>s.
</p>


<p id="res-4062"><b>Proposed resolution:</b></p>





</body>
</html>
