multi-dimensional array whole slicing

XavierAP via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Apr 25 14:12:38 PDT 2017


On Tuesday, 25 April 2017 at 20:46:24 UTC, Ali Çehreli wrote:
>
> I think it's still consistent because the element type is not 
> int in the case of multi-dimensional arrays.
> [...]
>     int[3][4] b;
>     b[] = [1, 1, 1];

It is consistent, I just miss the possibility to more easily 
initialize multi-dimensional arrays uniformly in the same way as 
uni-dimensional ones.

I do not mean it would be good to change the current behavior. I 
think the best solution would be for D to implement built-in 
truly multi-dimensional arrays like T[,] as well as the existing 
(jagged) arrays of arrays T[][]. That's what C# does. The former 
could maybe even be lowered into jagged arrays (together with 
their initializations and slicings).

But again most people probably don't miss T[,] built-in arrays, 
specially since we can implement such [,] indexing for custom 
types. So there's not a strong use case.

But actually where I'm using multi-dimensional built-in arrays 
right now is in the private storage of a custom multi-dimensional 
type. Then I have the choice of either use them and live with 
this, but forward indexing transparently; or use uni-dimensional 
as private storage and map from 2d to linear during indexing...


More information about the Digitalmars-d-learn mailing list