cannot modify struct with immutable members

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jan 3 01:05:06 PST 2015


On 01/02/2015 10:10 PM, ted wrote:

 > I'm now taking the view that const is there for the compiler to optimise
 > code on the basis that nothing can alter it once set (and can only be set
 > on initialisation).

Of course, that is true for const values, not for const references. In 
the latter case it means "I will not modify but others may modify", so 
the optimization that you mention does not apply to const in general. 
However, immutable can be used for optimization.

Ali



More information about the Digitalmars-d-learn mailing list