Comparison of two 'dynamic arrays'.
DLearner
bmqazwsx123 at gmail.com
Sun Nov 13 17:10:23 UTC 2022
On Sunday, 13 November 2022 at 16:11:17 UTC, matheus. wrote:
[...]
>
> You should add the code below after "auto B = A.dup;":
>
> B[0].Txt = A[0].Txt.dup;
>
> The "Txt" property inside B is still referencing A without the
> above.
>
> Matheus.
Thank you - your suggestion worked.
The slight generalisation shown at bottom also worked.
However, is there a way of avoiding the for-loop?
Things like
```
B[].Txt = A[].Txt.dup;
```
did not work for me.
```
void main() {
import std.stdio;
int index;
struct test_struct {
char[] Txt;
}
test_struct[] A;
A.length = 2;
A[0].Txt.length = 1;
A[1].Txt.length = 1;
A[0].Txt[0] = 'W';
A[1].Txt[0] = 'X';
writeln(A);
auto B = A.dup;
for (index = 0; index < A.length; index = index + 1) {
B[index].Txt = A[index].Txt.dup;
}
writeln(A, B);
A[0].Txt[0] = 'Y';
A[1].Txt[0] = 'Z';
writeln(A, B);
}
```
More information about the Digitalmars-d-learn
mailing list