mutable keyword
ag0aep6g via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat May 21 15:03:04 PDT 2016
On 05/21/2016 07:15 PM, Jack Applegame wrote:
> Really? Mutating immutable is UB too, but look at std.typecons.Rebindable.
Rebindable uses a union of a mutable and an immutable variant of the
type. No access to the mutable union member is provided, and it's never
dereferenced by Rebindable.
Assignment is done through the mutable member. So the immutable member
is never overwritten explicitly, but its value does change, of course.
It's supposedly not a problem that the immutable member changes, as long
as nobody looks. That is, as long as nobody obtains a reference to it.
Copies of the immutable member are truly immutable.
For this to work, the compiler must recognize that an immutable union
member isn't actually immutable when the union has mutable members as
well. I don't know if this is specified anywhere, or if it's perfectly
sound then.
And Rebindable does give out a reference, actually. That's unacceptable,
as far as I can see. Filed an issue:
https://issues.dlang.org/show_bug.cgi?id=16054
More information about the Digitalmars-d-learn
mailing list