.dup vs operation on all elements
Daniel Kozak
kozzi11 at gmail.com
Mon Dec 3 20:22:50 UTC 2018
Yes it is. The dup version just make an extra copy of array for no reason.
po 3. 12. 2018 21:10 odesílatel Goksan via Digitalmars-d-learn <
digitalmars-d-learn at puremagic.com> napsal:
> Are there any differences between these 2 methods of copying
> elements?
>
> double[] array = [ 1, 20, 2, 30, 7, 11 ];
>
> // Non dup
> double[6] bracket_syntax_dup = array;
> bracket_syntax_dup[] = array;
> bracket_syntax_dup[0] = 50;
>
> // Dup
> double[6] normal_dup = array.dup;
> normal_dup[0] = 100;
>
> OUTPUT: (array, bracket_syntax_dup and normal_dup respectively):
> [1, 20, 2, 30, 7, 11]
> [50, 20, 2, 30, 7, 11]
> [100, 20, 2, 30, 7, 11]
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20181203/5cd3ad60/attachment.html>
More information about the Digitalmars-d-learn
mailing list