DIP1000: Scoped Pointers (Discussion)

Lodovico Giaretta via Digitalmars-d digitalmars-d at puremagic.com
Fri Aug 12 03:34:02 PDT 2016


On Friday, 12 August 2016 at 10:24:22 UTC, Robert burner Schadek 
wrote:
>> No, the DIP doesn't handle several levels of indirection.
>
> What about:
>
> struct Bar { int a; int b }
> auto rcs = RefCountedTree!(string,Bar)();
>
> fcs["bar"].a = 1337;  // log n
> fcs["bar"].b = 1338;  // log n
>
> ? I need to pay log n twice to assign two members

What you are proposing is having the returned value survive not 
till the end of the expression, but longer. The question is how 
long. If, instead of a tree, you use an hashmap, then the 
reference to rcs["bar"] may die long before rcs itself (because 
of a rehash).
So for this to work the compiler should consider the references 
returned by the functions to be valid until a mutable operation 
is applied to the container, i think.


More information about the Digitalmars-d mailing list