opNext: Simplified ranges

Timon Gehr timon.gehr at gmx.ch
Mon Nov 7 21:01:55 UTC 2022


On 11/6/22 22:06, Per Nordlöw wrote:
> On Sunday, 6 November 2022 at 01:48:04 UTC, Walter Bright wrote:
>> We didn't use the "next" protocol for ranges because one cannot test 
>> for existence of the next element without consuming it.
> 
> That's not a blocker if we can afford implementing a second function for 
> the "peek" case. This is the path Rust took via its `Peekable` trait and 
> `peek()` member as described at
> 
> https://doc.rust-lang.org/stable/std/iter/struct.Peekable.html
> 
> .

This does more than just check for existence; the range will have to 
cache the next element, which is the issue OP is trying to fix I think.



More information about the Digitalmars-d mailing list