On Friday, 16 September 2016 at 17:11:54 UTC, Adam D. Ruppe wrote:
On Friday, 16 September 2016 at 17:03:20 UTC, Antonio Corbi wrote:
Is it safe to use or do I have to use the proposed 's[] = t;' or 's[] = t[]' ?

That works for all arrays. `s = t` for dynamically sized arrays (aka slices) just sets the references to the same, but for your statically sized arrays, it also copies.

Thank's Adam!

That's what my toy program told me:
import std.stdio;

alias matrix = uint[3][2];

int main(string[] args) {
  matrix s;
  matrix t = [[1,2,3],

  writeln ("s= ", s);
  writeln ("s.ptr= " , s.ptr);

  writeln ("t= ", t);
  writeln ("t.ptr= " , t.ptr);
  writeln ("t[1][2]= ", t[1][2]);

  s = t;

  writeln ("s= ", s);
  writeln ("s.ptr= " , s.ptr);

  return 0;

...but I wanted to be sure! :)

Shouldn't it be mentioned then in the docs that this works for statically sized arrays and that in that case it copies contents?

Reply via email to