Making RCSlice and DIP74 work with const and immutable

Manu via Digitalmars-d digitalmars-d at puremagic.com
Sat Feb 28 18:33:35 PST 2015


On 1 March 2015 at 12:22, Andrei Alexandrescu via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
> On 2/28/15 5:57 PM, Manu via Digitalmars-d wrote:
>>
>> Perhaps an operator that may be implemented to return a mutable
>> metadata pointer for objects? From an algebraic point of view, it
>> should be defined that mutating metadata will have no effect on the
>> actual object.
>
>
> But how would custom data be defined?

However the user likes? It would just be a mutable pointer. For RC, it
may just be an int*.


>> Interestingly, I wonder if such an approach may also be used to
>> satisfy a common problem that people have with const objects, where
>> it's not possible to implement caching systems for repeated work
>> optimisation?
>> The result cache is another thing that may be stored in the object's
>> metadata...?
>
>
> That's already abuse. No.

It's a very long-standing problem, one of the biggest recurring
complaints relating to the D type system, and the problem is of a very
similar nature; can't write to object because it's not mutable - but
we need this for RC, however may also be fine in caching cases because
cached results do not change the logical state of the object.
I see the same problem in both cases, and a good solution could
conceivably solve both problems.


More information about the Digitalmars-d mailing list