On Tuesday, 22 December 2020 at 16:53:11 UTC, jmh530 wrote:
For v = cast(size_t) x;I thought @safe prevented explicitly casting an immutable to a mutable, but the code below seems to suggest it is ok in this case...void main() @safe { immutable x = 32; auto v = cast(size_t) x; }
It's ok because you're making a copy. Casting from immutable to mutable is only dangerous when altering the mutable thing would affect the immutable thing, as it happens with pointers and such.