Getting the const-correctness of Object sorted once and for all

Jonathan M Davis jmdavisProg at gmx.com
Mon May 14 08:19:22 PDT 2012


On Monday, May 14, 2012 15:27:41 John wrote:
> On Monday, 14 May 2012 at 06:04:33 UTC, Mehrdad wrote:
> > On Monday, 14 May 2012 at 03:19:57 UTC, Jonathan M Davis wrote:
> >> I suspect that the folks who are looking for absolutely every
> >> CPU cycle and want caching and lazy-loading in their types
> > 
> > It's not a CPU cycle issue.
> > 
> > Caching/lazy-loading can make the difference between a window
> > that freezes, and a window that doesn't.
> 
> You can still do this pretty easily.  You just have to cast away
> const.

But that breaks the type system.

http://stackoverflow.com/questions/4219600/logical-const-in-d

Yes, you _can_ do it, but it's not actually guaranteed to work (casting away 
const and mutating a variable is _undefined_), and if you do it with an object 
which is actually immutable, then things could go _very_ wrong (e.g. 
segfault).

- Jonathan M Davis


More information about the Digitalmars-d mailing list