Differing semantics between multidimensional fixed-length array and slice initialization
monarch_dodra
monarchdodra at gmail.com
Mon Apr 1 04:08:01 PDT 2013
On Monday, 1 April 2013 at 10:52:34 UTC, Andrej Mitrovic wrote:
> On 4/1/13, Ali Çehreli <acehreli at yahoo.com> wrote:
>> Obviously, like C and C++, D does not have multi-dimensional
>> arrays but
>> D's array of array syntax is consistent.
>
> Does not have *rectangular* multi-dimensional arrays. :)
Actually, D does have partial support for multidimensional
rectangular arrays:
int[5][] rect = new int[5][](20);
...and there. A dynamic rectangular array of 20 by 5. Also, D
supports 1-line initialization for jagged rectangular arrays,
which is very convenient (but somewhat misleading in what it
does).
You can't do that in C++, due to the initialization syntax.
That said, in C++, if you use std::array ("semi-built-in"), then
you can do that. Further more, you can also allocate a single
static array on the heap with it. You can't do that with D (at
least, there is no standard container that emulates std::array,
which I think is a shame, it's very useful and efficient).
In any case, none of these languages support native rectangular
arrays of arbitrary sizes (let alone dimension). And none offer a
built-in container to do it either (though I think boost has
multi-dim something, but it requires a phd to use...)
More information about the Digitalmars-d-learn
mailing list