Proposed Changes to the Range API for Phobos v3
Steven Schveighoffer
schveiguy at gmail.com
Mon May 27 14:08:09 UTC 2024
On Thursday, 16 May 2024 at 14:56:55 UTC, Jonathan M Davis wrote:
> 5. Forward ranges will no longer have save. Rather, it will be
> required that copying a forward range will result in an
> independent copy. Both the original and the copy must then have
> the same elements in the same order, and iterating one will not
> affect the other. So, in essence, copying a forward range must
> be equivalent to calling save (though the actual implementation
> could be more clever than that).
So something I just thought of as a drawback here -- `save` gives
a nice explicit mechanism to copy when passing to a function that
takes a value by `auto ref`. In other words it *forces* non-ref
semantics so you do not affect the original.
Since passing to an `auto ref` function lets the compiler decide
to not make a copy, code that currently uses `save` for this
purpose doesn't have an equivalent in the new regime.
If we aren't going to have it, we might want to add a specialized
do-nothing UFCS function which just takes an lvalue and turns it
into an rvalue. Maybe we just call it `save`! Or maybe just a
boring `asRvalue`...
-Steve
More information about the Digitalmars-d
mailing list