[llvm] [ADT] Make Zippy more iterator-like for lifetime safety (PR #112441)
Geoff Romer via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 16 12:14:48 PDT 2024
geoffromer wrote:
> > I'm asking because IIRC returning values from the deref operator will become valid in C++20, so I wonder if we will have to fix it this way anyway later on.
>
> I had some vague sense of that too, but didn't find (admittedly didn't look terribly hard) details on this - do you happen to have pointers to the specifics here?
It's more of an addition than a change: the new iterator concepts like `std::forward_iterator` don't require `operator*` to return an lvalue, but the pre-C++20 "named requirements" like _ForwardIterator_ haven't changed, except that they're now called e.g. _LegacyForwardIterator_. See [P0022](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0022r2.html) for background. Note that it was written in 2016, so the details may have changed, but I believe it reflects the overall direction that was eventually adopted.
Ultimately, this isn't a question of whether the iterator is "valid", it's a question of what usages the iterator supports. Right now, the `zip` iterator doesn't support usages that require `operator*` to return an lvalue, which means it doesn't support being nested inside `concat`. Nothing in C++20 will cause those usages to start working; if you want them to work, you'll need to change the iterator to make them work.
https://github.com/llvm/llvm-project/pull/112441
More information about the llvm-commits
mailing list