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 read_only() sequence adaptor #69

Closed tcbrindle closed 1 year ago

tcbrindle commented 1 year ago

Otherwise known as as_const(), this behaves like a version of map() which returns a const reference from read_at() when the underlying sequence returns a mutable reference.

Actually, it does a bit more than that: using the formulation from P2278 (which in turn got it from range-v3) we define a new alias const_element_t<Seq>, returning std::common_reference_t<value_t<Seq> const&&, element_t<Seq>>. This does The Right Thing in all cases, including things like tuples and pairs of references if the stdlib has the latest C++23 changes.

We also define a new concept read_only_sequence<Seq>, satisfied when a sequence's element_t and const_element_t are the same type. This is mostly useful to avoid wrapping anything in read_only() when the underlying sequence is already const, but might be useful in other circumstances so we'll make it public.

codecov[bot] commented 1 year ago

Codecov Report

Patch and project coverage have no change.

Comparison is base (8ab832c) 97.70% compared to head (adf3cb5) 97.70%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #69 +/- ## ======================================= Coverage 97.70% 97.70% ======================================= Files 62 62 Lines 2045 2045 ======================================= Hits 1998 1998 Misses 47 47 ``` | [Impacted Files](https://app.codecov.io/gh/tcbrindle/flux/pull/69?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/69?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tristan+Brindle#diff-aW5jbHVkZS9mbHV4L2NvcmUvaW5saW5lX3NlcXVlbmNlX2Jhc2UuaHBw) | `90.90% <ø> (ø)` | |

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