Fully transitive const is not necessary

Simen Kjaeraas simen.kjaras at gmail.com
Thu Apr 3 05:38:30 PDT 2008


On Wed, 02 Apr 2008 16:50:12 +0200, Steven Schveighoffer  
<schveiguy at yahoo.com> 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.

-- Simen



More information about the Digitalmars-d mailing list