Re: how to append (ref) int[] to int[][]?

2020-06-08 Thread Paul Backus via Digitalmars-d-learn
On Monday, 8 June 2020 at 06:52:36 UTC, mw wrote: On Monday, 8 June 2020 at 06:42:44 UTC, Simen Kjærås wrote: Arrays (technically, slices) in D are essentially this struct: struct Array(T) { T* ptr; size_t length; // operator overloads } So when you have int[][], each element of

Re: how to append (ref) int[] to int[][]?

2020-06-08 Thread Dukc via Digitalmars-d-learn
On Monday, 8 June 2020 at 06:13:36 UTC, mw wrote: what I really want in (a) is append `ref arr` and output [[3], [3], [3]], i.e. the real `arr` be appended instead of its copy. I tried to change arrs' decl to: (ref (int[]))[] arrs; // the intended semantics I want 1) I'm wondering how

Re: how to append (ref) int[] to int[][]?

2020-06-08 Thread mw via Digitalmars-d-learn
On Monday, 8 June 2020 at 06:42:44 UTC, Simen Kjærås wrote: Arrays (technically, slices) in D are essentially this struct: struct Array(T) { T* ptr; size_t length; // operator overloads } So when you have int[][], each element of the outer array is an Array!int. These, as simple

Re: how to append (ref) int[] to int[][]?

2020-06-08 Thread Simen Kjærås via Digitalmars-d-learn
On Monday, 8 June 2020 at 06:13:36 UTC, mw wrote: Hi, I have this program: import std.stdio; void f(ref int[] arr) { arr ~= 3; } void main() { int[][] arrs; int[] arr; foreach (i; 0 .. 3) {

how to append (ref) int[] to int[][]?

2020-06-08 Thread mw via Digitalmars-d-learn
Hi, I have this program: import std.stdio; void f(ref int[] arr) { arr ~= 3; } void main() { int[][] arrs; int[] arr; foreach (i; 0 .. 3) { arr = new int[0]; arrs ~= arr; //(a)