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::ref() take a const reference by default #76

Closed tcbrindle closed 1 year ago

tcbrindle commented 1 year ago

Previously, flux::ref() did the same thing as std::ref(), except that the argument was required to be an lvalue sequence, and the result provided the inline sequence API to enable chaining.

Now, flux::ref() does the same as std::cref(), and requires the argument to be a const-iterable sequence.

The new flux::mut_ref() function does what the old ref() did, but requires that its argument is a non-const lvalue reference. (The name seems a bit "rusty", but there are only so many ways to abbreviate the word "mutable"...).

The idea is to promote "const by default", particularly when using references as for safety we want to avoid having multiple mutable references at one time if possible.

Finally, we also add member function versions of ref() and mut_ref(), taking const- and non-const lvalues respectively.

codecov[bot] commented 1 year ago

Codecov Report

Patch coverage: 100.00% and project coverage change: -0.01 :warning:

Comparison is base (970b391) 97.83% compared to head (2982ea2) 97.83%.

:exclamation: Current head 2982ea2 differs from pull request most recent head c47254c. Consider uploading reports for the commit c47254c to get more accurate results

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #76 +/- ## ========================================== - Coverage 97.83% 97.83% -0.01% ========================================== Files 64 64 Lines 2174 2173 -1 ========================================== - Hits 2127 2126 -1 Misses 47 47 ``` | [Impacted Files](https://app.codecov.io/gh/tcbrindle/flux/pull/76?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/76?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/from.hpp](https://app.codecov.io/gh/tcbrindle/flux/pull/76?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/76?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/76?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%> (ø)` | | ... and [1 file with indirect coverage changes](https://app.codecov.io/gh/tcbrindle/flux/pull/76/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tristan+Brindle)

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