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

Make flux::from() accept adaptable_sequences only #77

Closed tcbrindle closed 1 year ago

tcbrindle commented 1 year ago

This PR changes the flux::from() function so that it accepts only adaptable_sequences, wrapping them in a type that inherits from inline_sequence_base to enable chaining via member functions. If the passed-in sequence already inherits from inline_sequence_base it is returned by value unchanged.

Previously from() handled lvalues by calling ref() or mut_ref() depending on constness, but this had the unfortunate effect of making it harder to spot when references where being taken. With this change, the user now need to explicitly chose between from() (for rvalues) or ref()/mut_ref() for lvalues as appropriate.

There is one case this doesn't handle, which is where you have a forwarding reference to a sequence which you want to temporarily wrap in an adaptor for the duration of an algorithm call. (We do this in two places in the library, namely in the implementations of sort() and to().) For this case, this PR adds a from_fwd_ref() function which does what from() used to do -- but hopefully with a name that makes it more clear when it should be used.

codecov[bot] commented 1 year ago

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (06ddd52) 97.85% compared to head (413d08f) 97.85%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #77 +/- ## ======================================= Coverage 97.85% 97.85% ======================================= Files 65 65 Lines 2189 2191 +2 ======================================= + Hits 2142 2144 +2 Misses 47 47 ``` | [Impacted Files](https://app.codecov.io/gh/tcbrindle/flux/pull/77?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tristan+Brindle) | Coverage Δ | | |---|---|---| | [include/flux/op/from.hpp](https://app.codecov.io/gh/tcbrindle/flux/pull/77?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tristan+Brindle#diff-aW5jbHVkZS9mbHV4L29wL2Zyb20uaHBw) | `100.00% <100.00%> (ø)` | | | [include/flux/op/ref.hpp](https://app.codecov.io/gh/tcbrindle/flux/pull/77?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tristan+Brindle#diff-aW5jbHVkZS9mbHV4L29wL3JlZi5ocHA=) | `100.00% <100.00%> (ø)` | | | [include/flux/op/sort.hpp](https://app.codecov.io/gh/tcbrindle/flux/pull/77?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tristan+Brindle#diff-aW5jbHVkZS9mbHV4L29wL3NvcnQuaHBw) | `100.00% <100.00%> (ø)` | | | [include/flux/op/to.hpp](https://app.codecov.io/gh/tcbrindle/flux/pull/77?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tristan+Brindle#diff-aW5jbHVkZS9mbHV4L29wL3RvLmhwcA==) | `100.00% <100.00%> (ø)` | | | [include/flux/source/istreambuf.hpp](https://app.codecov.io/gh/tcbrindle/flux/pull/77?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tristan+Brindle#diff-aW5jbHVkZS9mbHV4L3NvdXJjZS9pc3RyZWFtYnVmLmhwcA==) | `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.