Difference between input range and forward range

Dominikus Dittes Scherkl via Digitalmars-d digitalmars-d at puremagic.com
Wed Nov 11 01:20:46 PST 2015


On Tuesday, 10 November 2015 at 18:57:31 UTC, Steven 
Schveighoffer wrote:
> IMO, that shouldn't be a forward range. But in any case, the 
> correct mechanism is:
>
> 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)
Hmm. You mean "b is no longer usable", right?

So, any algorithm requiring a copy should better do something like

static if(isForwardRange!range)
    copy = range;
else
    copy = range.save();



More information about the Digitalmars-d mailing list