On Thu, 05 Nov 2009 19:44:55 -0500, Walter Bright
<newshou...@digitalmars.com> wrote:
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.
But what if I don't what the whole function to be trusted, just that
creation section? I have to create a new function just to create the data?
Maybe function-level granularity isn't good enough...
-Steve