DIP1000: Scoped Pointers (Discussion)

deadalnix via Digitalmars-d digitalmars-d at puremagic.com
Fri Aug 12 03:04:19 PDT 2016


On Friday, 12 August 2016 at 09:42:35 UTC, Robert burner Schadek 
wrote:
> On Thursday, 11 August 2016 at 22:00:06 UTC, Walter Bright 
> wrote:
>> On 8/11/2016 4:46 AM, Robert burner Schadek wrote:
>>> Can I do this:
>>>
>>> ```
>>> struct Foo { int a; }
>>> auto rcs = RefCountedSlice!Foo(); // assume rcs.length > 0
>>>
>>> scope Foo zero = rcs[0];
>>> zero.a = 1337;
>>> assert(rcs[0].a == 1337);
>>> ```
>>
>> No, because the lifetime of zero exceeds the lifetime of 
>> rcs[0].
>
> Hm, that is really bad IMO. The shown use case is properly the 
> most common use case. Is there no way to make it transitive so 
> the lifetime of rcs[0] is the lifetime of rcs.
>
> To be blunt, this is a real show-stopper for me.

No, the DIP doesn't handle several levels of indirection.


More information about the Digitalmars-d mailing list