Closed brevzin closed 1 year ago
The test is easily fixable, so I'll do that (I think it dates from before I flipped the meaning of ref()
and added mut_ref()
, or maybe I just made a mistake).
Having read_only_adaptor
inherit from map_adaptor
is a neat idea (although I don't do it anywhere else). Does the access check work if you replace self.base_
with self.base()
?
The test is easily fixable, so I'll do that (I think it dates from before I flipped the meaning of
ref()
and addedmut_ref()
, or maybe I just made a mistake).
👍
Having
read_only_adaptor
inherit frommap_adaptor
is a neat idea (although I don't do it anywhere else). Does the access check work if you replaceself.base_
withself.base()
?
Oh yeah, that totally works! So yeah, my ... what... 25ish line implementation above there passes all the tests (with mut_ref
fixed).
I was literally just about to write that I've just tried it and it works! I'll have a PR in a couple of minutes
I thought I'd open an issue. Per twitter, this test: https://github.com/tcbrindle/flux/blob/b423b21d37f510f7793b6f1bf4e6e6f187fc9a4d/test/test_read_only.cpp#L18-L35
doesn't actually test anything about
read_only
, sinceflux::ref(arr)
is already a read-only sequence, soflux::read_only(flux::ref(arr))
(correctly!) just gives you backflux::ref(arr)
. You wantflux::mut_ref(arr)
there.This also begs the question of to what extend this is a valid implementation of
read_only
:It's very nearly correct, the only thing that should break is the
contiguous_sequence
check in the test. The fact thatread_only
is amap
, just one that's potentially contiguous, feels like it should be implemented like this:But that doesn't quite work. Another approach would be to have
flux::read_only
just returnflux::map
using the appopriatecast_to_const
and just havemap
recognize it. That feels a little backwards (why ismap
adding a function that is only usable forread_only
) but avoids all the boilerplate too.