Javari's Reference Immutability

Andrei Khropov andkhropov at nospam_mtu-net.ru
Tue Jul 25 05:27:25 PDT 2006


Reiner Pope wrote:

> The other alternative seems to be a much easier one: simply modify the vtbl
> so that all mutating functions point to a single line:
> 
>   assert(false, "Trying to modify a class through a readonly view");
> 
> The problem with that is that I suspect the vtable is stored with the class,
> not the reference, so modifying the vtable will modify it for all other
> references, even if they aren't readonly.

That problem is easy to solve:
Just have 2 vtables per class - one for mutable instances and one for readonly.

Cast to readonly will involve changing vtable ptr in the instance then.


-- 




More information about the Digitalmars-d-learn mailing list