mutable keyword
Jack Applegame via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun May 22 02:42:54 PDT 2016
On Saturday, 21 May 2016 at 21:49:23 UTC, Jonathan M Davis wrote:
> Rebindable is in kind of a weird grey area. It involves a
> union, not casting, and it's only ever mutating the class
> reference, not the object itself. Certainly, if it mutated the
> object, it would be undefined behavior, but it's just mutating
> the reference - but then again, the type system itself doesn't
> really differentiate between the two. So, I suspect that what
> it comes down to is that Rebindable is doing something that you
> really shouldn't, but because it's using a union rather than a
> cast, and it's so limited in what it's mutating, its behavior
> is effectively defined in the sense that the compiler has no
> leeway, but's probably still technically undefined. I don't
> know what Walter would say though. Certainly, if casting were
> involved, it would be undefined behavior without question, and
> it's not the sort of thing that you should be doing in your own
> code.
>
> [...]
I agree. But I think we need something that allows *logical*
const and immutable.
Strict binding constness to physical memory constancy is not
always necessary and sometimes even harmful.
More information about the Digitalmars-d-learn
mailing list