Re: a struct as an multidimensional array index

2022-06-11 Thread Ali Çehreli via Digitalmars-d-learn
On 6/11/22 13:36, z wrote: > i meant with the syntax in (1), the spec's documentation appears to say > they are equivalent in result with `new *type*[X][Y]` form. > > (1) https://dlang.org/spec/expression#new_multidimensional (3. multiple > argument form) Thank you. I see now: The values in pare

Re: a struct as an multidimensional array index

2022-06-11 Thread z via Digitalmars-d-learn
On Saturday, 11 June 2022 at 15:01:05 UTC, Ali Çehreli wrote: On 6/11/22 00:09, z wrote: > I rechecked and it should be `X Y Z` for static array, but `Z Y X` for > indexing/dynamic array creating with `new` How so? i meant with the syntax in (1), the spec's documentation appears to say they

Re: a struct as an multidimensional array index

2022-06-11 Thread Ali Çehreli via Digitalmars-d-learn
On 6/11/22 00:09, z wrote: > I rechecked and it should be `X Y Z` for static array, but `Z Y X` for > indexing/dynamic array creating with `new` How so? I wrote the following program: import std.stdio; void main() { enum X = 2; enum Y = 3; enum Z = 4; int[X][Y][Z] s; int[X][Y][] d =

Re: a struct as an multidimensional array index

2022-06-11 Thread Ali Çehreli via Digitalmars-d-learn
On 6/11/22 04:16, Salih Dincer wrote: > I think D is very consistent with our feelings. That is, the order in > memory is in the form of rows x columns. Yet, there are no rows or columns because neither D nor C (nor C++) have multip-dimensional arrays. They all have arrays where elements are la

Re: a struct as an multidimensional array index

2022-06-11 Thread Salih Dincer via Digitalmars-d-learn
On Friday, 10 June 2022 at 17:26:48 UTC, Ali Çehreli wrote: I've written about this multiple times in the past but D's way is consistent for me. That must be because I always found C's syntax to be very illogical on this. [...] I think so too... I think D is very consistent with our feelings.

Re: a struct as an multidimensional array index

2022-06-11 Thread z via Digitalmars-d-learn
On Saturday, 11 June 2022 at 03:56:32 UTC, Chris Katko wrote: On Friday, 10 June 2022 at 17:26:48 UTC, Ali Çehreli wrote: On 6/10/22 08:13, z wrote: > arrays of arrays has different order for declaration and addressing, > and declaring array of arrays has different order depending on how you >

Re: a struct as an multidimensional array index

2022-06-10 Thread Chris Katko via Digitalmars-d-learn
On Friday, 10 June 2022 at 17:26:48 UTC, Ali Çehreli wrote: On 6/10/22 08:13, z wrote: > arrays of arrays has different order for declaration and addressing, > and declaring array of arrays has different order depending on how you > declare it and wether it's static or dynamic array, *oof*) > >

Re: a struct as an multidimensional array index

2022-06-10 Thread Ali Çehreli via Digitalmars-d-learn
On 6/10/22 08:13, z wrote: > arrays of arrays has different order for declaration and addressing, > and declaring array of arrays has different order depending on how you > declare it and wether it's static or dynamic array, *oof*) > > To give you an idea of the situation : > ```D > int[3][1

Re: a struct as an multidimensional array index

2022-06-10 Thread Ali Çehreli via Digitalmars-d-learn
On 6/10/22 08:01, Ali Çehreli wrote: > I still don't understand the reason though. The rows would be copied > without ref but should retain their type as bool[3], a static array. (?) Ok, now I see the very sinister problem: It is a disaster to combine static array lambda parameters with the laz

Re: a struct as an multidimensional array index

2022-06-10 Thread z via Digitalmars-d-learn
On Friday, 10 June 2022 at 08:08:45 UTC, Chris Katko wrote: Is it somehow possible to use a struct as a [multidimensional] array index: D struct indexedPair { size_t x, y; } bool isMapPassable[100][100]; auto p = indexedPair(50, 50); if(isMapPassable[p]) return true; Probably not,

Re: a struct as an multidimensional array index

2022-06-10 Thread Ali Çehreli via Digitalmars-d-learn
On 6/10/22 07:38, Ali Çehreli wrote: > I played with that toString function but for some reason it prints all > Ts. (?) Fixed it by changing one of the lambdas to take by reference: void toString(scope void delegate(in char[]) sink) const { import std.algorithm; sink.formattedWrite!"%

Re: a struct as an multidimensional array index

2022-06-10 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jun 10, 2022 at 08:08:45AM +, Chris Katko via Digitalmars-d-learn wrote: > Is it somehow possible to use a struct as a [multidimensional] array index: > > D > > struct indexedPair > { > size_t x, y; > } > > bool isMapPassable[100][100]; > auto p = indexedPair(50, 50); > > if(is

Re: a struct as an multidimensional array index

2022-06-10 Thread Ali Çehreli via Digitalmars-d-learn
On 6/10/22 01:08, Chris Katko wrote: > Is it somehow possible to use a struct as a [multidimensional] array index: You can define an opIndex that takes any index type if the array is defined by you: import std.stdio; import std.format; struct indexedPair { size_t x, y; } struct MyArray {

a struct as an multidimensional array index

2022-06-10 Thread Chris Katko via Digitalmars-d-learn
Is it somehow possible to use a struct as a [multidimensional] array index: D struct indexedPair { size_t x, y; } bool isMapPassable[100][100]; auto p = indexedPair(50, 50); if(isMapPassable[p]) return true; Probably not, but I'm curious.