Closed tcbrindle closed 8 months ago
In the multipass version of flatten_adaptor
, we stop iterating when the outer cursor reaches the end of the outer sequence. However, when we get there, we don't reset the inner cursor, which is left pointing to wherever it previously pointed to. This means that a cursor which has iterated through to the end winds up not equal to the cursor returned from last()
(which contains a default-constructed inner cursor).
This showed up when using to()
because it uses (adapted) iterators which, of course, want to stop iterating when iter == last
. Since that equality never happened, we end up trying to read past the end. The good news is we got a bounds violation runtime error rather than UB -- the system works!
Anyway, the solution is to make sure we reset the inner cursor when we reach the end in multipass flatten_adaptor
. PR incoming...
Gives:
https://flux.godbolt.org/z/Eo3e9vrPM