Mutable ForwardRange save() method not callable using const object
Timoses
timosesu at gmail.com
Tue Sep 4 15:22:26 UTC 2018
On Tuesday, 4 September 2018 at 14:26:44 UTC, Steven
Schveighoffer wrote:
> [...]
> As general advice, I wouldn't expect const to work well with
> Ranges anyway -- const ranges are useless (you can't iterate
> them). So not much code is expecting to handle const, including
> the wrappers that Phobos provides.
Thanks, that sounds like some good advice. I've actually bumped
into this right after when I had an immutable range which was
supposed to fill in its cache when being iterated.
My argument for why this should work is that "from the outside of
the range" it is immutable, since accessing via opIndex will
always give the same value.
... In the end, that'll lead nowhere. The immutable attribute
would become a "promise" rather than an enforcement (or too hard
for the compiler to enforce).
Thanks for the clarification, Steve!
More information about the Digitalmars-d-learn
mailing list