On Tuesday, 25 October 2022 at 20:36:28 UTC, matheus wrote:
On
int[] a = [1];
int[] b = a.dup;
assert(&a[0] !is &b[0]); // different memory
```
This is interesting, I understand the point of "reference vs
copy", and I'm OK with this design choice of, but I wonder in
the case of newcomers if this is a case the generate more
problem understanding this rules, like we are having here.
Matheus.
Huh, I do NOT understand and I DO agree with you!
Excuse me, but they still write in purple prose about
dynamic&static array literature here!
I've known D for more than 10 years, but the topic we're talking
about still seems strange to me. The explanations given are not
enough for me, I'm sorry.
Can anyone tell me what happens when I change the location of the
structure? So the X structure must be in the stack when it is in
main(), and the following must be in the heap, right?
```d
import std;
//void main() {
struct X
{
struct Y {
int i = 10;
alias i this;
}
Y[] y = [Y.init];
string toString() {
return y.format!"%s";
}
}
void main() {
X[2] x;
x.writeln; // [[10], [10]]
x[0].y[0] = 0; // [[0], [0]]
x.writeln;
x[0].y.length++;
x[0].y[1] = 1;
x[1].y[0] = 2;
x.writeln; // [[0, 1], [2]]
} /* Output of other state:
[[10], [10]]
[[0], [0]]
[[2, 1], [2]]
*/
```
SDB@79