[idea] Mutable pointee/ RCString

Iakh via Digitalmars-d digitalmars-d at puremagic.com
Sun Feb 7 06:44:22 PST 2016


On Sunday, 7 February 2016 at 14:00:24 UTC, Iakh wrote:

Explanations:
As far as "immutable" transitive:
------
immutable RCString str;
*str.counter++; // Impossible/error/undefined behavior(with const 
cast)
------
Language defines immutable to do some optimizations based on true
constness of str, fields, and variables pointed by fields. But if
pointer would be treated by optimizer(not by GC) as void* (or 
size_t)
pointee "true constness" does not matter.

The only drawback is the immutable function that reads @mutable 
field
can't be @pure because it reads "global variable".


More information about the Digitalmars-d mailing list