July 28, 2015
On Tuesday, 28 July 2015 at 17:34:46 UTC, Steven Schveighoffer wrote:
> On 7/28/15 1:26 PM, Binarydepth wrote:
>> On Tuesday, 28 July 2015 at 17:07:47 UTC, Steven Schveighoffer wrote:
>>> On 7/28/15 12:59 PM, Binarydepth wrote:
>>
>>> When indexing, it always goes out to in. So nam[0] is the first
>>> element of type int[2], and nam[0][0] is the first integer in that
>>> first element.
>>
>>
>> I don't get what you mean here. In general I understood that in D
>> multidimensional arrays are a group of arrays.
>
> What I mean is the first index operation operates on the entire type. The second one operates on the element that the first retrieved, and so on.
>
> -Steve

I'm reading the reference : http://dlang.org/arrays.html

And I'm declaring two dynamic arrays as I understand. What I had in mind was declaring a dynamic array of two elements each.
July 29, 2015
On Tuesday, 28 July 2015 at 22:52:31 UTC, Binarydepth wrote:
> I'm reading the reference : http://dlang.org/arrays.html
>
> And I'm declaring two dynamic arrays as I understand. What I had in mind was declaring a dynamic array of two elements each.

int[2][] is exactly an dynamic array of (arrays with the length 2), the logic behind this notation is:
1. Array of 2 int -> int[2]
2. a dynamic array of 1. -> int[2][] (like SomeType[] is an array of SomeType)


If you define SomeType e.g. as
struct SomeType {
 int firstElement;
 int secondElement;
}
you get something similar.

Yes, this is different from e.g. Java, where new int[2][42] creates an array of 2 arrays with 42 elements each.

Accessing int[2][] nums :
1. nums[5] is the 5th element of nums which is of type int[2]
2. nums[5][0] is the zeroth element of 5th element of nums
 int[2] tmp = nums[5];
 int value = tmp[0];
does the same...
July 29, 2015
On Wednesday, 29 July 2015 at 08:03:06 UTC, anonymous wrote:
> int[2][] is exactly an dynamic array of (arrays with the length 2), the logic behind this notation is:
> 1. Array of 2 int -> int[2]
> 2. a dynamic array of 1. -> int[2][] (like SomeType[] is an array of SomeType)

Thank you!
1 2 3
Next ›   Last »