DIP1000: Scoped Pointers (Discussion)

Robert burner Schadek via Digitalmars-d digitalmars-d at puremagic.com
Fri Aug 12 02:42:35 PDT 2016


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.


More information about the Digitalmars-d mailing list