On 11/11/15 4:20 AM, Dominikus Dittes Scherkl wrote:
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?
Heh, right :)
So, any algorithm requiring a copy should better do something like
static if(isForwardRange!range)
copy = range;
else
copy = range.save();
No, it should do this:
static if(!isForwardRange!range)
assert(0, "I need a forward range")
save doesn't enter the picture, it would be eliminated. But again, this
isn't going to happen. Note my specification above is for a fictional
proposal of what I would have done.
The problem with the current save regime is that simple assignment for
forward ranges works too, but it doesn't always do what you want (and
diabolically, 99% of the time it DOES do what you want).
-Steve