Safety, undefined behavior, @safe, @trusted
Walter Bright
newshound1 at digitalmars.com
Thu Nov 5 16:44:55 PST 2009
Steven Schveighoffer wrote:
> That is, I have a mutable reference x, I want to make it immutable. How
> do you write a function to do that?
>
> i.e.:
>
> @safe void foo()
> {
> x = new X();
> x.modifyState(5);
> immutable(X) ix = ???; // how to write this part
> }
If you, the writer of foo(), know that there are no other mutable
references to x you can cast it to immutable - but you'll have to mark
the function as @trusted.
More information about the Digitalmars-d
mailing list