Difference between input range and forward range

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Tue Nov 10 10:38:22 PST 2015

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. Another would be 
std.range.refRange which exists specifically to turn a 
non-reference type range into a reference type range. And really, 
any range that's an input range but not a forward range is in 
that boat, because if copying it duplicated it, then it could be 
a forward range.

I really don't see any way around having something like save 
without artificially restricting ranges to types which are 
implicitly saved when copied (which would pretty much mean 
getting rid of pure input ranges), but even if there were clearly 
a better way, that's a pretty big change at this stage.

- Jonathan M Davis

More information about the Digitalmars-d mailing list