Logical const

Fawzi Mohamed fawzi at gmx.ch
Mon Nov 29 15:47:08 PST 2010


On 30-nov-10, at 00:04, Walter Bright wrote:

> Steven Schveighoffer wrote:
>> On Mon, 29 Nov 2010 15:58:10 -0500, Walter Bright <newshound2 at digitalmars.com 
>> > wrote:
>>> Steven Schveighoffer wrote:
>>>> Having a logical const feature in D would not be a convention, it  
>>>> would be enforced, as much as const is enforced.  I don't  
>>>> understand why issues with C++ const or C++'s mutable feature  
>>>> makes any correlations on how a D logical const system would  
>>>> fare.  C++ const is not D const, not even close.
>>>
>>>
>>> Because people coming from C++ ask "why not do it like C++'s?"
>> I don't get it.  A way to make a field mutable in a transitively- 
>> const system is syntactically similar to C++, but it's not the  
>> same.  Having a logical-const feature in D does not devolve D's  
>> const into C++'s const.  If anything it's just a political problem.
>
> Having mutable members destroys any guarantees that const provides.  
> That's not political.
>
> And, I repeat, having a mutable type qualifier DOES NOT make logical  
> const a language feature. This is why discussion and understanding  
> of C++'s const system is so important - people impute  
> characteristics into it that it simply does not have.

logical const is useful for lazy functions and memoization, and if  
implemented correctly it is perfectly safe.
As I said in an older discussions, to have it with the current system  
all that is needed is some guarantees that the compiler will not  
disallow "unsafe" changes (by moving to read only memory for  
example)in some cases.
For example casted mutable types, so that casting to mutable works.

Fawzi


More information about the Digitalmars-d mailing list