Difference between input range and forward range
Steven Schveighoffer via Digitalmars-d
digitalmars-d at puremagic.com
Tue Nov 10 10:57:31 PST 2015
On 11/10/15 1:38 PM, Jonathan M Davis wrote:
> On Tuesday, 10 November 2015 at 17:16:41 UTC, Steven Schveighoffer wrote:
>> I've never made it a secret that I dislike the 'save' requirement. In
>> my experience, the only time you ever implement 'save' is to do the
>> same thing as copying the range via =. To the point where people
>> simply don't use the .save member, and their code always works, so
>> what is the point? It may as well have been an enum isCopyable.
> Well, it's not that hard to come up with a range that has to implement
> save, because copying it doesn't save it. The obvious example is if it's
> implemented as a class.
IMO, that shouldn't be a forward range. But in any case, the correct
forward range -> a = b works and makes a copy of the iteration.
non-forward range -> a = b fails, you'd have to use a = b.getRef or
something like that -or- a = b is a moving operation (a is no longer usable)
Classes wouldn't work with this because you can't overload assignment,
but the whole range hierarchy system cannot be changed at this point
anyway. Moving on...
More information about the Digitalmars-d