Array operations
monkyyy
crazymonkyyy at gmail.com
Fri May 2 22:38:51 UTC 2025
On Friday, 2 May 2025 at 22:19:53 UTC, Andy Valencia wrote:
> In the following code, two questions. First, is there any
> difference between "x[] = y" and "x[] = y[]"?
With basic slices no; I could construct something with overloads
tho
```d
import std.stdio : writeln;
auto foo(ref int[] a, ref int[] b){
a=b;
}
auto bar(ref int[] a, ref int[] b){
a=b[];
}
void foobar(alias F)(){
int[] x = new int[4];
int[] y = new int[8];
F(x,y);
(x.ptr-y.ptr).writeln;
(x.length-y.length).writeln;
}
void main() {
foobar!foo;
foobar!bar;
}
```
x and y are as far as I know, bit for bit identical and nothing
can cause spookieness in either case
> I'm curious why they stepped away from D's exception
> architecture?
Slices are references... mostly; its spooky when they overlap
with dynamic arrays; with this instruction your going to be
reassigning a pointer.
More information about the Digitalmars-d-learn
mailing list