Forward ranges in Phobos v2

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Nov 2 02:45:11 UTC 2021


On 11/1/21 8:13 PM, Paul Backus wrote:
> On Tuesday, 2 November 2021 at 00:05:48 UTC, Alexandru Ermicioi wrote:
>> On Monday, 1 November 2021 at 23:46:07 UTC, H. S. Teoh wrote:
>>> Good question, ask Andrei. ;-)
>>
>> Well, I hope he will check this thread and comment on it.
>>
>>> Presumably, if we standardize on structs/classes, it could be as 
>>> simple as:
>>>
>>>     auto myFunc(R)(R range) if (is(R == struct)) {
>>>         ... // forward range
>>>     }
>>>
>>>     auto myFunc(R)(R range) if (is(R == class)) {
>>>         ... // input range
>>>     }
>>>
>>> But given that Andrei thinks it's a mistake for ranges to be 
>>> implemented as classes, I've no idea.
>>
>> That would work, if you have templated funcs, but what if you need it 
>> in an interface?
>>
>> If class based ranges are to be in D language, I doubt it will be 
>> possible to avoid .save function completely. At least for range 
>> interfaces, the save of forward range will have to be expressed 
>> through a method, such as .save.
> 
> You can always wrap a class/interface method in a struct that calls 
> .save on copy:

Exactly. No need to support class ranges - simple wrappers can do 
everything class-like indirection does. Thanks.



More information about the Digitalmars-d mailing list