Comparison of two 'dynamic arrays'.
DLearner
bmqazwsx123 at gmail.com
Sun Nov 13 15:45:40 UTC 2022
On Sunday, 13 November 2022 at 14:39:26 UTC, Siarhei Siamashka
wrote:
> On Sunday, 13 November 2022 at 14:28:45 UTC, DLearner wrote:
>> Creating a step 1.5:
>> ```
>> int[] B = A;
>> ```
>
> ```D
> auto B = A.dup;
> ```
>
> This will create a copy of A rather than referencing to the
> same buffer in memory.
Tested:
```
void main() {
import std.stdio;
struct test_struct {
char[] Txt;
}
test_struct[] A;
A.length = 1;
A[0].Txt.length = 1;
A[0].Txt[0] = 'X';
writeln(A);
auto B = A.dup;
writeln(A, B);
A[0].Txt[0] = 'Y';
writeln(A, B);
}
```
Got:
```
[test_struct("X")]
[test_struct("X")][test_struct("X")]
[test_struct("Y")][test_struct("Y")]
```
Expected last line to be Y,X not Y,Y.
More information about the Digitalmars-d-learn
mailing list