|
|
|
|
|
by brabel
881 days ago
|
|
Wow that seems pretty unsafe... In D, for example, this works as most people would expect: import std.stdio;
void main() {
int[] a = [1, 2, 3, 4, 5];
auto lo = a[0 .. 2], hi = a[2 .. $];
lo ~= [6,7,8]; // new allocation
writefln("%s %s", lo, hi); // prints [1, 2, 6, 7, 8] [3, 4, 5]
}
You simply can't overwrite a backing array from a slice (unless you do unsafe stuff very explicitly). |
|