Idea: Immutable blocks within functions
Peter Alexander
peter.alexander.au at gmail.com
Sat Sep 7 16:05:30 PDT 2013
On Saturday, 7 September 2013 at 22:57:40 UTC, Xinok wrote:
> immutable
> {
> int[] arr = ...;
> int[] arr2 = arr.dup;
> sort(arr); // arr is still mutable
>
> int[] arr2 = arr.dup;
> reverse(arr2);
> arr ~= arr2;
> }
How do you stop mutable references escaping in functions called
from the immutable block?
e.g.
int* p;
void foo(ref int x) { p = &x; }
void main()
{
immutable
{
int x = 1;
foo(x);
}
*p = 0;
}
More information about the Digitalmars-d
mailing list