Code security: "auto" / Reason for errors
Adam D. Ruppe via Digitalmars-d
digitalmars-d at puremagic.com
Wed Mar 2 11:50:38 PST 2016
On Wednesday, 2 March 2016 at 19:42:02 UTC, Ozan wrote:
> I despair of "auto var1 = var2"for arrays. Isn't it a open door
> for errors. Example
> int[] a;
> foreach(i; 0..10) a ~= i;
> auto b = a; // correct dlang coding: auto b = a.dup;
It'd do exactly the same thing if you wrote
int[] b = a;
so the auto changes nothing there. Generally, the slice
assignment is a good thing because it gives you easy efficiency
and doesn't hide the costs of a duplicate.
More information about the Digitalmars-d
mailing list