Fully transitive const is not necessary
Christian Kamm
kamm.incasoftware at shift-at-left-and-remove-this.de
Wed Apr 2 12:33:50 PDT 2008
>> class C
>> {
>> mutable int x;
>> void foo() const { x++; } // const but can't be pure
>> void bar() pure
>> { /* can't do anything in here you couldn't have done above */ }
>> }
Janice Caron wrote:
> But you could equally well write it like this:
>
> class C
> {
> int x;
> void foo() { x++; }
> void bar() pure
> { /* can't do anything in here you couldn't have done above */ }
> }
>
> If it can change, then don't call it const. Seems a simple enough rule to
> me.
Yes, but now const's transitivity isn't a necessity for 'future
multiprogramming features' anymore. Instead, we're discussing a const
scheme where mutable members could be allowed, but aren't - for simplicity,
consistency or some other reason.
I have not used D2 yet, so I'm not sure it is as restricting as some people
suggest. From the outside transitive const certainly looks simpler and more
useful than C++'s variant. However, if there are several genuine cases
where escapes from transitivity would be advantageous, allowing exceptions
should be considered.
More information about the Digitalmars-d
mailing list