On Monday, 30 March 2015 at 19:08:24 UTC, anonymous wrote:
On Monday, 30 March 2015 at 18:37:53 UTC, matovitch wrote:
On Monday, 30 March 2015 at 18:34:19 UTC, Adam D. Ruppe wrote:
[...]
Aye, that would work too, but the slice I think is more
efficient as I'm pretty sure... not completely sure, but I
think .array makes a copy of static arrays, whereas the slice
doesn't.
I was going to ask you the question does it just add the range
shell or does it make a copy ? :/ Maybe someone else know.
Let's check the documentation.
http://dlang.org/phobos/std_array.html#array says: "Allocates
an array and initializes it with copies of the elements of
range r." Documentation says copy.
Let's check the actual behaviour.
----
void main()
{
int[1] a = [1];
import std.array: array;
a.array[0] = 2;
import std.stdio: writeln;
writeln(a[0]);
}
----
(also at <http://dpaste.dzfl.pl/1191144a9acf>)
This program prints "1". That's the output we'd expect when
`array` makes a copy. Actual behaviour says copy.
So, copy.
That settle the point for array as for [] ? I guess the
documentation should have something to say about it too. ;)