Forward ranges in Phobos v2
Atila Neves
atila.neves at gmail.com
Fri Nov 5 11:35:47 UTC 2021
On Thursday, 4 November 2021 at 15:29:59 UTC, Andrei Alexandrescu
wrote:
> On 11/4/21 12:43 AM, Paul Backus wrote:
>> On Thursday, 4 November 2021 at 04:06:15 UTC, Andrei
>> Alexandrescu wrote:
>>> On 11/3/21 11:25 PM, Paul Backus wrote:
>>>> [...]
>>>
>>> That was on the table, too, in the form of a raw pointer.
>>>
>>> I think it can be made to work, but for lvalue ranges only,
>>> and it will be difficult to make safe (scoped etc).
>>>
>>> Overall this seems to create more problems than it solves.
>>
>> I'd be curious to see any examples of such problems you have
>> in mind.
>>
>> As far as I'm aware, no special effort should be required to
>> make this @safe, aside from enabling -preview=dip1000 (which,
>> granted, is still a work in progress).
>
> Pointers are problematic because of aliasing and lifetime (what
> if the pointer survives the data structure it points into).
T* should mean infinite lifetime by default in @safe code: where
did you get that pointer to begin with? If a struct contains a T*
within it, then scoped struct variables solve the lifetime issue
that way. Aliasing, however, is a problem we still have. Which is
why we can't currently write a @safe vector.
> Note that the whole thing still doesn't address unbuffered
> ranges. There must be a buffer of at least one element
> somewhere. That's... problematic.
Yeah, I'm still wondering how to fix that.
More information about the Digitalmars-d
mailing list