Fully transitive const is not necessary

Janice Caron caron800 at googlemail.com
Wed Apr 2 09:22:50 PDT 2008


On 02/04/2008, Steven Schveighoffer <schveiguy at yahoo.com> wrote:
> "Janice Caron" wrote
>
> > On 02/04/2008, Steven Schveighoffer wrote:
>  >> "Janice Caron" wrote
>  >>  > pure requires transitive const.
>  >>
>  >>  Forgive me if I don't take your word for it.  Please prove this.
>  >>  Specifically, why pure fails with logical const (not head const as C++
>  >> is).

> I'm assuming you meant f to be part of Stupid?

No, that was just a typo. Or lazy typing - take your pick. I should have written


    not_pure void f(const(Stupid) stupid)
    {
        int t = stupid.y;
        ++stupid.t;
        stupid.y = t;
    }

Try calling f from two threads at the same time, imagine a thread
switch partway through f.


>  - a pure method cannot access the mutable portion of a logically invariant
>  data value.

Well, the easy way to do that is to redesign the class into two
classes, one const and the other not. That way, you get the exact same
benefit, but in addition, you end up saying what you mean, instead of
writing obfuscated code.



More information about the Digitalmars-d mailing list