Fully transitive const is not necessary

Steven Schveighoffer schveiguy at yahoo.com
Thu Apr 3 07:35:22 PDT 2008


"Simen Kjaeraas" wrote
> On Wed, 02 Apr 2008 16:50:12 +0200, Steven Schveighoffer  wrote:
>
>> "Simen Kjaeraas" wrote
>>> On Wed, 02 Apr 2008 16:41:33 +0200, Steven Schveighoffer  wrote:
>>>
>>>> "Simen Kjaeraas" wrote
>>>>> On Wed, 02 Apr 2008 16:04:36 +0200, Steven Schveighoffer  wrote:
>>>>>
>>>>>> - a pure method cannot access the mutable portion of a logically
>>>>>> invariant data value.
>>>>>
>>>>> Wouldn't this basically make it transitive invariant?
>>>>
>>>> Yes, which makes my point :)  pure must be transitive, but const /
>>>> invariant
>>>> by itself does not need to be.
>>>>
>>>> -Steve
>>>
>>> So yes, you can do without transitive const, as long as you define 
>>> logical
>>> const as transitive. I can't quite see what point you're trying to make.
>>
>> No, I'm not defining logical const as transitive.  I'm defining that 
>> pure is
>> transitive.  pure functions have nothing to do with requiring const to be
>> transitive, which is my point.
>>
>> Did you look at my example in the original post?  What we have now is
>> semantically equivalent to logical const.
>>
>> -Steve
>
> Yes, there are ways to bypass the const system. We know that, and we 
> accept it. Why not just do:
>
> class foo
> {
>   int bar;
>   const void baz()
>   {
>     (cast(foo)this).bar++;
>   }
> }
>
> That also works.

There is a huge difference between my code and your code.  My code is 
well-defined by the language spec, yours is not.  I hope to never write 
undefined code, as I'm not sure it will always work.

-Steve 





More information about the Digitalmars-d mailing list