Multi-dimensional fixed arrays

Justin Whear via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jun 30 15:04:24 PDT 2015


On Tue, 30 Jun 2015 21:02:37 +0000, DLearner wrote:

> Out of curiosity, why can't D define a 2-dim array by something like:
> int(2,1) foo;
> 
> which defines two elements referred to as:
> foo(0,0) and foo(1,0)?
Work is being done on multidimensional slicing, see this thread:
http://forum.dlang.org/post/dyvzmjfcjzoxvitwbylf@forum.dlang.org
> 
> It just seems unnatural (if not actually dangerous) to me to have the
> array index order reverse between definition and use.

Think about it this way:

alias IntList = int[10];
IntList[3] myIntLists;
int[10][3] myOtherIntLists; // same type as above

You build the type up from the innermost layer to the outermost and when 
you access the data you reverse that operation, slicing deeper and deeper.


More information about the Digitalmars-d-learn mailing list