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

Paul Backus snarwin at gmail.com
Mon Jun 8 12:00:48 UTC 2020


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 the outer array is 
>> an Array!int. These, as simple structs, are copied about, so 
>> that changing one does not change another.
>
> Thank you for the reply, I think this explanation should be 
> added to the top of https://dlang.org/spec/arrays.html
>
> Then people (esp with C/C++ background) can easily understand 
> D's array behavior.

A good explanation of D's arrays (which should really be called 
"slices") is available in the "Articles" section of dlang.org:

https://dlang.org/articles/d-array-article.html


More information about the Digitalmars-d-learn mailing list