Casting away immutability
Mike Parker via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Sep 3 07:36:09 PDT 2015
On Thursday, 3 September 2015 at 13:28:54 UTC, Sergei Degtiarev
wrote:
> Agree, however, memory obtained with mmap(..., PROT_READ, ..);
> is essentially read-only and any attempt to write to it will
> cause immediate crash with segmentation violation. It would be
> very desirable in this case to return something that could be
> cast to immutable(type)[] but not type[].
> This is what I tried to find out. Thank you for the help.
immutable(T)[] getGetData(T)() {
return cast(immutable(T)[])data;
}
...
auto ints = obj.getData!int;
More information about the Digitalmars-d-learn
mailing list