std.v2020.algorithm etc[ WAS: Is run.d going to be expand for runtime and the phobos library?]

Stanislav Blinov stanislav.blinov at gmail.com
Sun Jun 21 00:38:31 UTC 2020


On Sunday, 21 June 2020 at 00:05:01 UTC, Andrei Alexandrescu 
wrote:
> On 6/20/20 12:41 PM, Stanislav Blinov wrote:
>> Being able to call front() several times does not necessitate 
>> the *range* being buffering.
>
> If one calls front() twice without advancing the range, where 
> does the range return the value from?

The most primitive example? The range is lazy and builds the 
element on every call. But I believe I've tried to make the 
distinction clear: *range* itself isn't necessarily buffering. 
Whatever it's iterating over may have to.

And, in case that wasn't clear either, I understand perfectly 
where you're coming from, since typical input ranges do indeed 
have to memoize that nasty first element upon initialization (and 
since they have to do that, they have to repeat that for every 
element thenceforth). Thing is, the input stream

`bool fetchNext(ref T);`

does not solve this problem, it merely shrugs it off unto the 
caller, with precarious consequences, as demonstrated.


More information about the Digitalmars-d mailing list