forked from lwg/issues
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New issue from Barry: "Reversing an infinite range leads to an infini…
…te loop"
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?xml version='1.0' encoding='utf-8' standalone='no'?> | ||
<!DOCTYPE issue SYSTEM "lwg-issue.dtd"> | ||
|
||
<issue num="4019" status="New"> | ||
<title>Reversing an infinite range leads to an infinite loop</title> | ||
<section><sref ref="[range.reverse]"/></section> | ||
<submitter>Barry Revzin</submitter> | ||
<date>25 Nov 2023</date> | ||
<priority>99</priority> | ||
|
||
<discussion> | ||
<p> | ||
Consider the following: | ||
</p> | ||
<blockquote><pre> | ||
auto a = views::iota(0) | views::reverse; | ||
auto b = views::repeat(42) | views::reverse; | ||
</pre></blockquote> | ||
<p> | ||
Here, <tt>views::iota(0)</tt> and <tt>views::repeat(42)</tt> are both non-common bidirectional (even random-access) ranges. | ||
They are also infinite ranges, even if the standard doesn't really recognize that. | ||
<p/> | ||
<tt>views::reverse</tt> on a non-common range will actually compute the end iterator for you. So while both declarations | ||
of <tt>a</tt> and <tt>b</tt> above compile, attempting to use either in any way will lead to an infinite loop when you | ||
<tt>try a.begin()</tt> or <tt>b.begin()</tt>. | ||
<p/> | ||
A reddit posts suggests disallowing reversing a non-common range but that likely breaks reasonable use-cases. We could at | ||
the very least recognize ranges whose sentinel is <tt>unreachable_t</tt> and reject those from consideration. For instance, | ||
we could change <sref ref="[range.iter.op.next]"/>/3 to <i>Mandate</i> that <tt>S</tt> is not <tt>unreachable_t</tt>. | ||
</p> | ||
</discussion> | ||
|
||
<resolution> | ||
</resolution> | ||
|
||
</issue> |