const(FAQ)

guslay guslay at gmail.com
Fri Mar 28 21:55:07 PDT 2008


Walter Bright Wrote:

> The same questions about const come up repeatedly, so I decided that it 
> was past time to put up a FAQ dedicated to const. The initial version is 
> far from complete, but it's a start.
> 
> http://www.digitalmars.com/d/2.0/const-faq.html


>From my experience, the need for logical constness is a rare occurrence, but it invariably happens as projects that adhere to a const regime grow. With the const system in D offering must stronger guarantees than in C++ (which is a good thing), the need for logical const is even larger.

I have a hard time figuring how const-correctness can work for large projects (which is one thing D const is intended to help) without that flexibility.

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

- 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) )?





More information about the Digitalmars-d mailing list