Logical const

Walter Bright newshound2 at digitalmars.com
Tue Nov 30 11:02:14 PST 2010


Peter Alexander wrote:
> Just to clarify my position
> 
> - I *do not* want to copy C++'s const system.
> - D style immutability is useful.
> - C++ style logical const is also useful.
> - I think they can both work side by side by introducing a new level of 
> const and the mutable keyword.


Once mutable is introduced, the const attribute becomes no longer useful. You 
(and the compiler) can no longer look at a function signature and reason about 
the const-ness behavior. If a new attribute is introduced, "newlevel", you 
really cannot reason about the behavior at all.

I wish to emphasize that the compiler cannot provide any verification that 
logical constness is indeed happening. (It cannot do it in C++, either, the 
notion that the C++ type system supports logical constness is incorrect.)


More information about the Digitalmars-d mailing list