Making array elements truly const/immutable

Adam D. Ruppe destructionator at gmail.com
Thu Aug 2 05:25:28 PDT 2012


If a function is marked @safe, casting away immutable is
not allowed by the compiler.

But, you can't put this on the array. It needs to be on
the user's functions:

@safe void foo(immutable(ubyte)[] arr) {
    auto cheating = cast(ubyte[]) arr;
}

test2.d(2): Error: cast from immutable(ubyte)[] to ubyte[] not 
allowed in safe code



More information about the Digitalmars-d-learn mailing list