How to break const

Timon Gehr timon.gehr at gmx.ch
Wed Jun 20 04:23:18 PDT 2012


On 06/20/2012 09:16 AM, deadalnix wrote:
> Le 19/06/2012 17:49, Timon Gehr a écrit :
>>
>> The question is, what the meaning of 'const' references should be:
>>
>> 1. data cannot be changed transitively through the reference
>>
>> 2. the reference can reference both 'const' and 'immutable' data and
>> 'immutable' data can transitively not be changed through the
>> reference.
>>
>>
>> 1. requires transitive const for delegate context pointers, 2. does not.
>>
>
> No, 2. require 1., even if the initialization is broken.
>
> class Foo {
>      void delegate() dg;
>
>      this(immutable void delegate() dg) immutable {
>          thid.dg = dg;
>      }
> }
>
> Now, as delegate doesn't carry the constness of its context, an
> immutable instance of Foo can refers to something that isn't immutable.

Clarification: 'const' means 'const'. No other qualifiers.

There is no 'const' in that example code. 'immutable' obviously needs to 
be transitive regardless of the particular interpretation of 'const'.



More information about the Digitalmars-d mailing list