On Wednesday, 29 May 2013 at 15:14:54 UTC, Kenji Hara wrote:
With 2.063, this code would work.
struct S { int* ptr; } // has mutable indirection
void main()
{
immutable S si = function () pure
{
S sm;
sm.ptr = new int;
*sm.ptr = 10;
return sm; // construct and return mutable object
}();
static assert(is(typeof(*si.ptr) == immutable int));
assert(*si.ptr == 10);
}
The local function would return an unique object, so it is
implicitly
convertible to immutable.
Kenji Hara
Hm, well the problem isn't to make something mutable into
immutable, so the purity and implicit conversion is not
necessary, but using a nested or anonymous function would indeed
be a good way to move the problematic try-catch into another
function.