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 S.B. Tam: "P2609R3 breaks code that uses views::zip an…
…d get<T>"
- Loading branch information
Showing
1 changed file
with
46 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,46 @@ | ||
<?xml version='1.0' encoding='utf-8' standalone='no'?> | ||
<!DOCTYPE issue SYSTEM "lwg-issue.dtd"> | ||
|
||
<issue num="4171" status="New"> | ||
<title>P2609R3 breaks code that uses `views::zip` and <tt>get<T></tt></title> | ||
<section><sref ref="[indirectcallable.indirectinvocable]"/></section> | ||
<submitter>S. B. Tam</submitter> | ||
<date>01 Nov 2024</date> | ||
<priority>99</priority> | ||
|
||
<discussion> | ||
<p> | ||
The following use of `std::ranges::for_each` is valid before <paper num="P2609R3"/> and invalid after that. | ||
</p> | ||
<blockquote><pre> | ||
#include <algorithm> | ||
#include <ranges> | ||
#include <tuple> | ||
using namespace std::ranges; | ||
|
||
void f() { | ||
int a[1]; | ||
auto fun = [](auto t) { | ||
[[maybe_unused]] auto x = std::get<int&>(t); | ||
}; | ||
for_each(views::zip(a), fun); | ||
} | ||
</pre></blockquote> | ||
<p> | ||
The reason is that, <paper num="P2609R3"/> requires `fun` to be `invocable` with <tt>iter_value_t<I>&</tt>, | ||
which is <tt>tuple<int>&</tt> when `I` is `zip_view`'s iterator, and <tt>tuple<int>&</tt> | ||
doesn't support <tt>std::get<int&>(t)</tt> because there isn't a <tt>int&</tt> member. | ||
<p/> | ||
P2609R3 argues that "The actual consequence on user code seems small", but I believe that this code pattern is | ||
common enough, and it hurts if we cannot use <tt>get<int&>(t)</tt> in the lambda body. | ||
<p/> | ||
Note that `for_each` doesn't actually call `fun` with <tt>iter_value_t<I></tt>, as can be seen by adding | ||
an explicit return type to `fun`. | ||
<p/> | ||
Did LWG foresee this impact of <paper num="P2609R3"/>? Could P2609R3 be reverted to unbreak this code pattern? | ||
</p> | ||
</discussion> | ||
|
||
<resolution> | ||
</resolution> | ||
</issue> |