Forward ranges in Phobos v2

Andrei Alexandrescu SeeWebsiteForEmail at erdani.com
Tue Nov 2 21:58:20 UTC 2021


On 2021-11-02 17:44, Dukc wrote:
> 
>> What's a value range?
> 
> Opposite of a reference range - copying implies `save()`.

Yah, one simple improvement we could make is to assume all forward 
ranges copy their iteration state when copying the range. Then input 
ranges do NOT do that, i.e. all copies of an input range refer to the 
same stream and iterate it together (advancing one advances all).

The differentiation can be made with a nested enum tag:

struct MyInputRange {
     enum inputRangeTag = true;
     ...
}

Client code can inspect R.inputRangeTag to figure whether the range is 
input (if present) or forward (if missing).


More information about the Digitalmars-d mailing list