tcbrindle / flux

A C++20 library for sequence-orientated programming
https://tristanbrindle.com/flux/
Boost Software License 1.0
476 stars 29 forks source link

Add cursors() adaptor #75

Closed tcbrindle closed 1 year ago

tcbrindle commented 1 year ago

Given a sequence seq, cursors(seq) returns a new sequence whose elements are, unsurprisingly, the cursors of the original sequence. The cursors sequence retains all the capabilities of the source sequence (bidir, RA, sized etc), not including contiguous_sequence.

This is basically a passthrough adaptor, except that read_at(seq, cur) just returns a copy of cur. (The copy is required because read_at accepts a const reference for its second argument, which can be initialised with a temporary, which can otherwise cause lifetime issues.)

Unlike every other adaptor function, cursors() takes an lvalue reference as its argument (all the others behave as if they take their arguments by value). The reason is that generally you can't do anything with a cursor unless you have its original sequence still available, so almost every real-world use of cursors() will actually want to do flux::ref(seq).cursors() which is a lot more typing, so cursors() basically does the ref bit for you.

However, this goes against the Flux principle that long-lived references should be explicitly formed by the user, and is inconsistent with all the other adaptor functions so I'm not sure it's really a good idea.

EDIT: I changed my mind, cursors() now requires adaptable_sequence like all the other adaptors.

codecov[bot] commented 1 year ago

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.01 :tada:

Comparison is base (8459b7e) 97.83% compared to head (1a341cb) 97.85%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #75 +/- ## ========================================== + Coverage 97.83% 97.85% +0.01% ========================================== Files 64 65 +1 Lines 2173 2189 +16 ========================================== + Hits 2126 2142 +16 Misses 47 47 ``` | [Impacted Files](https://app.codecov.io/gh/tcbrindle/flux/pull/75?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tristan+Brindle) | Coverage Δ | | |---|---|---| | [include/flux/core/inline\_sequence\_base.hpp](https://app.codecov.io/gh/tcbrindle/flux/pull/75?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tristan+Brindle#diff-aW5jbHVkZS9mbHV4L2NvcmUvaW5saW5lX3NlcXVlbmNlX2Jhc2UuaHBw) | `91.66% <ø> (ø)` | | | [include/flux/op/cursors.hpp](https://app.codecov.io/gh/tcbrindle/flux/pull/75?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tristan+Brindle#diff-aW5jbHVkZS9mbHV4L29wL2N1cnNvcnMuaHBw) | `100.00% <100.00%> (ø)` | |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.