Why do we have transitive const, again?

Jonathan M Davis jmdavisProg at gmx.com
Sun Sep 25 14:12:53 PDT 2011


On Sunday, September 25, 2011 11:12:10 bearophile wrote:
> Timon Gehr:
> > I think it should be a language feature, as proposed by Jonathan.
> 
> I did miss his post. I see he has turn that idiom into a language feature
> :-)
> From Jonathan's post:
> > 2. __varLoaded is default-initialized to false, and __var is void (so,
> > garbage).
> The GC has to read __varLoaded and then scan the contents of __var only if
> __varLoaded is true.
> 
> To do this in user code (or code rewritten by front-end rules) time ago I
> have suggested to add this simple standard method to D:
> 
> bool onGC(string fieldName)() {...}
> 
> That if present is called by the GC during its scan, to know if a
> union/struct/clas method needs to be scanned now (I did invent it for
> unions, but it's useful for structs too, it seems).

Well, the big thing with my proposal is that it allows you to have lazy 
loading with the existing const. It doesn't attempt to introduce a new type of 
const or to solve the general issue of logical constness - just the lazy 
loading of a member variable which could have an expensive computation.

- Jonathan M Davis


More information about the Digitalmars-d mailing list