Logical const

Walter Bright newshound2 at digitalmars.com
Tue Nov 30 13:53:14 PST 2010


Steven Schveighoffer wrote:
> If you find the above unsurprising, you are in the minority.  I find it 
> surprising, and invalid that anyone would write code this way.  People 
> simply just don't do that normally.  It's just written to demonstrate a 
> point that the compiler does not guarantee anything via const, it's 
> guaranteed by convention.  The compiler simply helps you follow the 
> convention.

Ok, I see what you mean now. Your code is relying on there being a mutable alias 
of the same object.

This is not surprising behavior. It is explicit in how const is defined. It 
makes sense that const does not have immutable behavior, because otherwise there 
wouldn't be both const and immutable type constructors.

You're wrong in saying the compiler doesn't guarantee anything with const. I 
listed the things it does guarantee.


More information about the Digitalmars-d mailing list