RFP - name for input range method
Paul Backus
snarwin at gmail.com
Thu Apr 2 15:32:42 UTC 2020
On Thursday, 2 April 2020 at 14:09:14 UTC, Steven Schveighoffer
wrote:
[...]
> The draconian solution is to make input ranges not copyable.
> That is, you have to be made aware that making a copy can
> destroy the original range. Then we can eliminate `save`, and a
> forward range just becomes a copyable input range.
>
> But at the same time, a good point from Jonathan Davis buried
> somewhere in a recent thread is that making ranges not copyable
> is quite painful. The most obvious example is that
> foreach(elem; range) makes a copy of range. What if you make a
> copy and just don't use the original (like when you pass to a
> function)? What if you only just use front on the original?
> What if you actually *want* to iterate some of the data off of
> the range in the copy, and do the rest with the original?
>
> The current situation is going to result constantly in more of
> these WTF instances.
Walter has a draft DIP in the works [1] to implicitly move
objects instead of copying them when you "make a copy and just
don't use the original". It seems to me like this would make
non-copyable ranges much more ergonomic to use, without requiring
any changes to the existing range interface.
[1]
https://github.com/WalterBright/DIPs/blob/13NNN-WGB.md/DIPs/13NNN-WGB.md
More information about the Digitalmars-d
mailing list