const(FAQ)

Walter Bright newshound1 at digitalmars.com
Fri Mar 28 23:29:12 PDT 2008


guslay wrote:
> - Could you elaborate more on what mutable members would
> break/prevent, if used reasonably?

"reasonably" is not a factor. The point of compiler enforcement is you 
won't be relying on whether programmers are reasonable or not - it 
offers a guarantee.

> - If I do need mutable members in a const method (for lazy
> evaluation, caching, counter), what should I do? Is there technique
> you can propose to escape it (e.g. a way I can externalize the
> mutable part (seems difficult because of the transitive nature of
> const) )?

It can't be done with transitive const. My suggestion for such things is 
to use private data members, and read the values with property functions.




More information about the Digitalmars-d mailing list