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.

Reply via email to