Forward ranges in Phobos v2

Paul Backus snarwin at gmail.com
Wed Nov 3 16:18:01 UTC 2021


On Wednesday, 3 November 2021 at 15:40:41 UTC, Andrei 
Alexandrescu wrote:
> On 2021-11-02 20:38, Paul Backus wrote:
>> 
>> auto next(R)(ref R r)
>>      if (isForwardRangeV2!R && isMutable!R)
>> {
>>      alias E = ElementType!R;
>>      if (r.empty)
>>          return none!E();
>>      else
>>      {
>>          auto result = some(r.head);
>>          r = r.tail;
>>          return result;
>>      }
>> }
>
> OK, so the signature of next for all ranges is:
>
> Option!(ElementType!R) next(Range)(ref Range);
>
> Is that correct?

More precisely, to use the Phobos convention: 
`is(ReturnType!((Range r) => r.next) == Option!(ElementType!R))`.

So, `next` could be a function, a @property, or a member 
variable, and it does not necessarily require an lvalue to call 
(just like `front` today).


More information about the Digitalmars-d mailing list