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

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

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

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 >

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

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

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;

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];

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 MyAr

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.

Re: Initialization of dynamic multidimensional array

2017-02-10 Thread berni via Digitalmars-d-learn
On Friday, 10 February 2017 at 09:34:39 UTC, berni wrote: On Friday, 10 February 2017 at 09:25:04 UTC, Daniel Kozak wrote: Now I tried this with a named instead of a magic constant e.g. immutable VALUE=-1; arr.each!"a[]=VALUE"; And it doesn't work anymore. I've no clue, why... Can you help

Re: Initialization of dynamic multidimensional array

2017-02-10 Thread berni via Digitalmars-d-learn
On Friday, 10 February 2017 at 09:25:04 UTC, Daniel Kozak wrote: Now I tried this with a named instead of a magic constant e.g. immutable VALUE=-1; arr.each!"a[]=VALUE"; And it doesn't work anymore. I've no clue, why... Can you help me? Because it does not see VALUE, you need to use

Re: Initialization of dynamic multidimensional array

2017-02-10 Thread Mike Parker via Digitalmars-d-learn
On Friday, 10 February 2017 at 09:03:16 UTC, berni wrote: Now I tried this with a named instead of a magic constant e.g. immutable VALUE=-1; arr.each!"a[]=VALUE"; And it doesn't work anymore. I've no clue, why... Can you help me? each is a template. As per the template documentation

Re: Initialization of dynamic multidimensional array

2017-02-10 Thread Daniel Kozak via Digitalmars-d-learn
Dne 10.2.2017 v 10:03 berni via Digitalmars-d-learn napsal(a): On Tuesday, 7 February 2017 at 19:06:22 UTC, berni wrote: auto arr = uninitializedArray!(int[][])(ROWS,COLS); arr.each!"a[]=-1"; This looks like what I was looking for. At least I think I understand what's going on here. The

Re: Initialization of dynamic multidimensional array

2017-02-10 Thread berni via Digitalmars-d-learn
On Tuesday, 7 February 2017 at 19:06:22 UTC, berni wrote: auto arr = uninitializedArray!(int[][])(ROWS,COLS); arr.each!"a[]=-1"; This looks like what I was looking for. At least I think I understand what's going on here. The other two suggestions are beyond my scope yet, but I'll come back,

Re: Initialization of dynamic multidimensional array

2017-02-07 Thread berni via Digitalmars-d-learn
auto arr = uninitializedArray!(int[][])(ROWS,COLS); arr.each!"a[]=-1"; This looks like what I was looking for. At least I think I understand what's going on here. The other two suggestions are beyond my scope yet, but I'll come back, when I improved on my D skills. Thanks for your replies.

Re: Initialization of dynamic multidimensional array

2017-02-07 Thread Ilya Yaroshenko via Digitalmars-d-learn
On Sunday, 5 February 2017 at 20:33:06 UTC, berni wrote: With X not known at compile time: auto arr = new int[][](X,X); for (int i=0;i

Re: Initialization of dynamic multidimensional array

2017-02-06 Thread Ali Çehreli via Digitalmars-d-learn
On 02/05/2017 12:33 PM, berni wrote: With X not known at compile time: auto arr = new int[][](X,X); for (int i=0;i

Re: Initialization of dynamic multidimensional array

2017-02-06 Thread Daniel Kozak via Digitalmars-d-learn
One another way is use something like this: import std.array, std.algorithm, std.stdio; auto arr = uninitializedArray!(int[][])(ROWS,COLS); arr.each!"a[]=-1"; writeln(arr); Dne 6. 2. 2017 8:21 PM napsal uživatel "berni via Digitalmars-d-learn" < digitalmars-d-learn@puremagic.com>: > On Sunday, 5

Re: Initialization of dynamic multidimensional array

2017-02-06 Thread berni via Digitalmars-d-learn
On Sunday, 5 February 2017 at 21:14:33 UTC, Daniel Kozak wrote: http://stackoverflow.com/questions/24600796/d-set-default-value-for-a-struct-member-which-is-a-multidimensional-static-arr/24754361#24754361 Dne 5.2.2017 v 21:33 berni via Digitalmars-d-learn napsal(a): With X not known at

Re: Initialization of dynamic multidimensional array

2017-02-05 Thread Daniel Kozak via Digitalmars-d-learn
http://stackoverflow.com/questions/24600796/d-set-default-value-for-a-struct-member-which-is-a-multidimensional-static-arr/24754361#24754361 Dne 5.2.2017 v 21:33 berni via Digitalmars-d-learn napsal(a): With X not known at compile time: auto arr = new int[][](X,X); for (int i=0;i

Initialization of dynamic multidimensional array

2017-02-05 Thread berni via Digitalmars-d-learn
With X not known at compile time: auto arr = new int[][](X,X); for (int i=0;i

Re: Multidimensional array access

2016-12-20 Thread somebody via Digitalmars-d-learn
Thanks for the explanation

Re: Multidimensional array access

2016-12-20 Thread Ali Çehreli via Digitalmars-d-learn
On 12/20/2016 11:59 AM, somebody wrote: I though D should have syntax similarities with C, but recently I've found that array indexing in D is different. Suppose we have a code: import std.stdio; void main () { wstring[6][2] strings; strings[2][0] = "test"; } It fails to compile

Re: Multidimensional array access

2016-12-20 Thread Madaz Hill via Digitalmars-d-learn
On Tuesday, 20 December 2016 at 19:59:41 UTC, somebody wrote: I though D should have syntax similarities with C, but recently I've found that array indexing in D is different. Suppose we have a code: import std.stdio; void main () { wstring[6][2] strings; strings[2][0] = "test"; }

Multidimensional array access

2016-12-20 Thread somebody via Digitalmars-d-learn
I though D should have syntax similarities with C, but recently I've found that array indexing in D is different. Suppose we have a code: import std.stdio; void main () { wstring[6][2] strings; strings[2][0] = "test"; } It fails to compile because of error: "./main.d(6): Error:

Re: multidimensional array

2014-09-30 Thread Joel via Digitalmars-d-learn
Thanks JKPdouble. I was hoping for a clear way to work multidimensional arrays out.

multidimensional array

2014-09-28 Thread Joel via Digitalmars-d-learn
I'm trying to make a multidimensional array. I feel I've tried every thing. Is there a good guide explaining it? struct Spot { bool dot; } spots = new Spot[][](800,600); assert(spots[800-1][600-1].dot, Out of bounds);

Re: multidimensional array

2014-09-28 Thread JKPdouble via Digitalmars-d-learn
On Sunday, 28 September 2014 at 04:24:25 UTC, Joel wrote: I'm trying to make a multidimensional array. I feel I've tried every thing. Is there a good guide explaining it? struct Spot { bool dot; } spots = new Spot[][](800,600); assert(spots[800-1][600-1].dot, Out of bounds); dot

Re: multidimensional array

2014-09-28 Thread JKPdouble via Digitalmars-d-learn
On Sunday, 28 September 2014 at 04:38:56 UTC, JKPdouble wrote: On Sunday, 28 September 2014 at 04:24:25 UTC, Joel wrote: I'm trying to make a multidimensional array. I feel I've tried every thing. Is there a good guide explaining it? struct Spot { bool dot; } spots = new Spot[][](800,600

Re: multidimensional array

2014-09-28 Thread ketmar via Digitalmars-d-learn
On Sun, 28 Sep 2014 04:24:19 + Joel via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: struct Spot { bool dot; } spots = new Spot[][](800,600); btw, does anybody know why i can do `new ubyte[256];` but not `new ubyte[256][256];`? hate that. signature.asc Description: PGP

Re: multidimensional array

2014-09-28 Thread Stefan Frijters via Digitalmars-d-learn
On Sunday, 28 September 2014 at 04:24:25 UTC, Joel wrote: I'm trying to make a multidimensional array. I feel I've tried every thing. Is there a good guide explaining it? struct Spot { bool dot; } spots = new Spot[][](800,600); assert(spots[800-1][600-1].dot, Out of bounds); You

Re: multidimensional array

2014-09-28 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Sep 28, 2014 at 10:48:45AM +0300, ketmar via Digitalmars-d-learn wrote: On Sun, 28 Sep 2014 04:24:19 + Joel via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: struct Spot { bool dot; } spots = new Spot[][](800,600); btw, does anybody know why i can do `new

Re: multidimensional array

2014-09-28 Thread Stewart Gordon via Digitalmars-d-learn
On 28/09/2014 08:48, ketmar via Digitalmars-d-learn wrote: On Sun, 28 Sep 2014 04:24:19 + Joel via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: struct Spot { bool dot; } spots = new Spot[][](800,600); btw, does anybody know why i can do `new ubyte[256];` but not `new

Re: multidimensional array

2014-09-28 Thread ketmar via Digitalmars-d-learn
On Sun, 28 Sep 2014 07:40:23 -0700 H. S. Teoh via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: File a bug. https://issues.dlang.org/show_bug.cgi?id=13556 signature.asc Description: PGP signature

Re: multidimensional array

2014-09-28 Thread ketmar via Digitalmars-d-learn
On Sun, 28 Sep 2014 22:33:40 +0100 Stewart Gordon via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: You can do `new ubyte[256][256]`, if the destination type is a ubyte[256][]. The reason is that you are performing an allocation of the form `new T[n]`, which means allocate an

Re: Using std.algorithm how to uniq and sort a multidimensional array?

2014-01-29 Thread bearophile
Meta: auto tags = tags.flatMap!uniq.array ? That's another solution. In Phobos a flatMap can be useful (just as a zip overload that accepts a function to apply on the pairs, named zipWith in haskell: http://zvon.org/other/haskell/Outputprelude/zipWith_f.html ). Bye, bearophile

Re: Using std.algorithm how to uniq and sort a multidimensional array?

2014-01-28 Thread Gary Willoughby
On Tuesday, 28 January 2014 at 14:46:48 UTC, Gary Willoughby wrote: Using std.algorithm how to uniq and sort a multidimensional array? e.g. the uniq function takes a function as a predicate but i'm confused how to handle the multiple dimensions. string[][] tags; tags = tags.uniq

Re: Using std.algorithm how to uniq and sort a multidimensional array?

2014-01-28 Thread Meta
On Tuesday, 28 January 2014 at 15:07:26 UTC, bearophile wrote: Gary Willoughby: string[][] tags; tags = tags.uniq!(a[0][1] == b[1][1]).array; I think the right abstraction for your use case is: auto tags = tags.flatten.uniq.array; auto tags = tags.flatMap!uniq.array ?

Multidimensional array in d2?

2013-11-14 Thread seany
I See that in stack exchange, that it is possible to create multidimensional arrays like : type [][] arrayname ; and here : http://homepages.uni-regensburg.de/~nen10015/documents/D-multidimarray.html that such is not possible. I would like to know more about it, and learn about

Re: Multidimensional array in d2?

2013-11-14 Thread Ali Çehreli
On 11/14/2013 01:18 PM, seany wrote: I See that in stack exchange, that it is possible to create multidimensional arrays like : type [][] arrayname ; That works because in C, C++, D, etc. a multi-dimensional array is nothing but a single dimensional array where elements are arrays. I

Re: Multidimensional array in d2?

2013-11-14 Thread seany
Oh, this is really nice, thank you very much I also note you have a book http://ddili.org/ders/d.en/index.html (too bad that there are chapters not translated, but thank you very much)! On Thursday, 14 November 2013 at 21:24:25 UTC, Ali Çehreli wrote: On 11/14/2013 01:18 PM, seany wrote:

Re: Multidimensional array in d2?

2013-11-14 Thread Ali Çehreli
On 11/14/2013 01:31 PM, seany wrote: I also note you have a book http://ddili.org/ders/d.en/index.html (too bad that there are chapters not translated, but thank you very much)! You are very welcome! Just three chapters left and I must add the UDA chapter, which has been one of the most

Re: Multidimensional array

2013-07-06 Thread TommiT
On Friday, 5 July 2013 at 01:31:00 UTC, Ali Çehreli wrote: But this doesn't compile: char[3][5] arr = [ '.', '.', '.' ]; Error: mismatched array lengths, 15 and 3 I see that as a bug but can't be sure. I'd file a bug report, but since [x, y, z] is primarily a dynamic array literal, I'd

Re: Multidimensional array

2013-07-06 Thread Ali Çehreli
On 07/05/2013 09:00 PM, Oleksiy wrote: Look like there is a consequence - can't perform array-wise operations on multidimensional arrays? I don't want to accept that conclusion because there is no such thing as a multidimensional array in D. :) (To be fair, they don't exist in C and C

Re: Multidimensional array

2013-07-05 Thread bearophile
Ali Çehreli: int[3][2] arr = 10; I would expect that to be an error because the element type is not an int but int[3]. We know that an int[3] can be initialized by 10 but a 10 should not be allowed to be used as an int[3]. That was my point. I see. That's another feature :-) Bye,

Re: Multidimensional array

2013-07-05 Thread monarch_dodra
On Friday, 5 July 2013 at 01:43:45 UTC, bearophile wrote: There is a way to specify the type of a string, so this gives errors: void main() { string s1 = xxd; string s2 = xxw; wstring s3 = xxd; } Bye, bearophile Also, don't forget the often forgotten explicit c suffix: dstring

Re: Multidimensional array

2013-07-05 Thread monarch_dodra
On Thursday, 4 July 2013 at 23:02:10 UTC, Jonathan M Davis wrote: On Friday, July 05, 2013 00:39:47 Oleksiy wrote: Hi, I'm new to the language and would appreciate if anybody could clarify the following: 1. What is the rationale behind prefix declaration of an array? Using right-to-left

Re: Multidimensional array

2013-07-05 Thread monarch_dodra
On Friday, 5 July 2013 at 01:53:22 UTC, Ali Çehreli wrote: Now I have another array where the elements are of type int[3]: int[3][2] arr = [ 10, 20, 30 ]; Error: mismatched array lengths, 6 and 3 Ali Combined with the fact that *this* works: int[3][2] arr = [ 10, 20, 30, 10, 20, 30 ];

Re: Multidimensional array

2013-07-05 Thread Oleksiy
Fixing it so that the sizes for static arrays were read left-to-right would definitely be a usability improvement, but even if we were to decide that the whole read the type outward from the variable name was unimportant enough to make the change desirable, it would silently break all kinds of

Re: Multidimensional array

2013-07-05 Thread Oleksiy
However, that is a confusing syntax because the right-hand side is not the same type as the elements, which is dchar[3]. Perhaps D supports it for C compatibility? Yes, I noticed: arr = '!'; Error: cannot implicitly convert expression ('!') of type char to dchar[3u][] Look like there is a

Multidimensional array

2013-07-04 Thread Oleksiy
Hi, I'm new to the language and would appreciate if anybody could clarify the following: 1. What is the rationale behind prefix declaration of an array? Using right-to-left order to declare an array and left-to-right order to access elements seems confusing. 2. Consider this code:

Re: Multidimensional array

2013-07-04 Thread Jonathan M Davis
On Friday, July 05, 2013 00:39:47 Oleksiy wrote: Hi, I'm new to the language and would appreciate if anybody could clarify the following: 1. What is the rationale behind prefix declaration of an array? Using right-to-left order to declare an array and left-to-right order to access

Re: Multidimensional array

2013-07-04 Thread bearophile
Oleksiy: 1. What is the rationale behind prefix declaration of an array? Using right-to-left order to declare an array and left-to-right order to access elements seems confusing. I think the way Go language declares arrays and pointers is a bit better. But for the rationale of this part of

Re: Multidimensional array

2013-07-04 Thread Ali Çehreli
On 07/04/2013 03:39 PM, Oleksiy wrote: 1. What is the rationale behind prefix declaration of an array? Using right-to-left order to declare an array and left-to-right order to access elements seems confusing. It seems to be confusing to people who are used to C and C++'s inside-out

Re: Multidimensional array

2013-07-04 Thread bearophile
Ali Çehreli: However, that is a confusing syntax because the right-hand side is not the same type as the elements, which is dchar[3]. Perhaps D supports it for C compatibility? It doesn't match the following. Here, the right-hand side is the same as the element type: int[2] arr2 = 42;

Re: Multidimensional array

2013-07-04 Thread Ali Çehreli
On 07/04/2013 06:43 PM, bearophile wrote: Ali Çehreli: However, that is a confusing syntax because the right-hand side is not the same type as the elements, which is dchar[3]. Perhaps D supports it for C compatibility? It doesn't match the following. Here, the right-hand side is the same

Re: Duplicating multidimensional array

2013-05-30 Thread Ali Çehreli
On 05/29/2013 10:22 AM, Joseph Rushton Wakeling wrote: I've been having some trouble trying to work out how to effectively duplicate a multidimensional array in a way that preserves type qualifiers. Templates preserve type qualifiers. So, as long as the return type is the same

Re: Duplicating multidimensional array

2013-05-30 Thread Joseph Rushton Wakeling
one multidimensional array to another.

Re: Duplicating multidimensional array

2013-05-30 Thread Ali Çehreli
On 05/30/2013 03:02 PM, Joseph Rushton Wakeling wrote: I would never have thought of that trick with the second template parameter. Phobos is a source of ideas. ;) I guess it might fall over with complex structs or classes, though. :-\ Copying structs is trivial because they already have

Re: Duplicating multidimensional array

2013-05-30 Thread Joseph Rushton Wakeling
On 05/31/2013 01:48 AM, Ali Çehreli wrote: Copying structs is trivial because they already have copy semantics: T b = a; // b is a copy of a However, that depends on correctly implemented copy semantics on T. By complex structs I meant things like structs containing arrays -- a

Re: Duplicating multidimensional array

2013-05-30 Thread Ali Çehreli
On 05/30/2013 04:48 PM, Ali Çehreli wrote: For classes, there is no syntax for copying. The type may have annotated a member function that it is the duplication function or we may know by convention that dup() is the equivalent of array .dup. Kenji Hara responded to another thread on the

Duplicating multidimensional array

2013-05-29 Thread Joseph Rushton Wakeling
Hello all, I've been having some trouble trying to work out how to effectively duplicate a multidimensional array in a way that preserves type qualifiers. Now, obviously if we have a multidimensional array such as T[][] then calling .dup will duplicate only the base array; so if we do something

Re: Fixed size multidimensional array at runtime

2012-07-01 Thread Denis Shelomovskij
01.07.2012 0:06, Vidar Wahlberg пишет: On Saturday, 30 June 2012 at 19:35:33 UTC, Denis Shelomovskij wrote: Thanks for the tip, that is interesting (I'm surprised I didn't come across this post when searching for this issue earlier). Although it seems to me that you still end up with matrix[x,

Re: Fixed size multidimensional array at runtime

2012-07-01 Thread Roman D. Boiko
On Sunday, 1 July 2012 at 09:52:22 UTC, Denis Shelomovskij wrote: 01.07.2012 13:46, Denis Shelomovskij пишет: So I deliberately disallow rule `matrix[x]` means `matrix[x, R[]...]` and made `byTopDimension` property for such iteration:

Re: Fixed size multidimensional array at runtime

2012-07-01 Thread Vidar Wahlberg
On Sunday, 1 July 2012 at 09:46:52 UTC, Denis Shelomovskij wrote: I'm curious why do you need such syntax? `matrix[x][y][z]` expression means that `matrix[x]` is also a valid expression but it shouldn't. It's not a syntax I need, it's a syntax I desire as that's the syntax I'm used to for

Re: Fixed size multidimensional array at runtime

2012-07-01 Thread Denis Shelomovskij
01.07.2012 16:02, Vidar Wahlberg пишет: On Sunday, 1 July 2012 at 09:46:52 UTC, Denis Shelomovskij wrote: I'm curious why do you need such syntax? `matrix[x][y][z]` expression means that `matrix[x]` is also a valid expression but it shouldn't. It's not a syntax I need, it's a syntax I desire

Re: Fixed size multidimensional array at runtime

2012-07-01 Thread Vidar Wahlberg
On Sunday, 1 July 2012 at 12:21:59 UTC, Denis Shelomovskij wrote: No, that is the syntax you used for arrays of arrays. In D, yes. In other languages I'm familiar with, such as Java, that syntax is used for rectangular arrays. I've grown to like the syntax as used in Java and I wanted to

Re: Fixed size multidimensional array at runtime

2012-07-01 Thread Artur Skawina
On 06/30/12 22:06, Vidar Wahlberg wrote: Although it seems to me that you still end up with matrix[x, y, z] instead of matrix[x][y][z], so it will only solve one half of the problem :) For this particular case I'll just do the conversion from two-dimensional to one-dimensional array

Re: Fixed size multidimensional array at runtime

2012-07-01 Thread Vidar Wahlberg
On Sunday, 1 July 2012 at 12:21:59 UTC, Denis Shelomovskij wrote: No, that is the syntax you used for arrays of arrays. In D, yes. In other languages I'm familiar with, such as Java, that syntax is used for rectangular arrays. I've grown to like the syntax as used in Java and I wanted to

Fixed size multidimensional array at runtime

2012-06-30 Thread Vidar Wahlberg
I know multidimensional arrays has been brought up many times, although I was not able to find a clear answer to my question. My knowledge of what's going on behind the curtains is somewhat lacking, please correct me if my assumptions are incorrect. Creating a dynamic multidimensional array

Re: Fixed size multidimensional array at runtime

2012-06-30 Thread Jonathan M Davis
are incorrect. Creating a dynamic multidimensional array can be easily achieved with for example auto matrix = new int[][](4, 2);, although if I've understood it correct this would create a jagged array (as explained on page 112 in TDPL) which may cause efficiency issues due to two

Re: Fixed size multidimensional array at runtime

2012-06-30 Thread Vidar Wahlberg
On Saturday, 30 June 2012 at 18:32:09 UTC, Jonathan M Davis wrote: In D, static arrays are always fixed in size, and that size must be known at compile time, whereas dynamic arrays are never fixed in size (unless they're immutable), and the size doesn't need to be known at compile time. There

Re: Fixed size multidimensional array at runtime

2012-06-30 Thread Jonathan M Davis
On Saturday, June 30, 2012 21:01:02 Vidar Wahlberg wrote: On Saturday, 30 June 2012 at 18:32:09 UTC, Jonathan M Davis wrote: In D, static arrays are always fixed in size, and that size must be known at compile time, whereas dynamic arrays are never fixed in size (unless they're

Re: Fixed size multidimensional array at runtime

2012-06-30 Thread Vidar Wahlberg
On Saturday, 30 June 2012 at 19:06:31 UTC, Jonathan M Davis wrote: On Saturday, June 30, 2012 21:01:02 Vidar Wahlberg wrote: This is a very good suggestion, I hadn't thought of this possibility, this way I can get my beloved matrix[x][y]; instead of something like matrix.get(x, y);. It might

Re: Fixed size multidimensional array at runtime

2012-06-30 Thread Jonathan M Davis
On Saturday, June 30, 2012 21:27:15 Vidar Wahlberg wrote: On Saturday, 30 June 2012 at 19:06:31 UTC, Jonathan M Davis wrote: On Saturday, June 30, 2012 21:01:02 Vidar Wahlberg wrote: This is a very good suggestion, I hadn't thought of this possibility, this way I can get my beloved

Re: Fixed size multidimensional array at runtime

2012-06-30 Thread Denis Shelomovskij
. Creating a dynamic multidimensional array can be easily achieved with for example auto matrix = new int[][](4, 2);, although if I've understood it correct this would create a jagged array (as explained on page 112 in TDPL) which may cause efficiency issues due to two indirections as opposed to only one

Re: Fixed size multidimensional array at runtime

2012-06-30 Thread Vidar Wahlberg
On Saturday, 30 June 2012 at 19:35:33 UTC, Denis Shelomovskij wrote: You could be interested in my answer on this thread: http://forum.dlang.org/thread/mailman.1578.1339962782.24740.digitalmars-d-le...@puremagic.com Thanks for the tip, that is interesting (I'm surprised I didn't come across

Re: Fixed size multidimensional array at runtime

2012-06-30 Thread Roman D. Boiko
On Saturday, 30 June 2012 at 20:06:58 UTC, Vidar Wahlberg wrote: On Saturday, 30 June 2012 at 19:35:33 UTC, Denis Shelomovskij wrote: You could be interested in my answer on this thread: http://forum.dlang.org/thread/mailman.1578.1339962782.24740.digitalmars-d-le...@puremagic.com Thanks for

Re: [D1,static array] fill static multidimensional array.

2010-10-22 Thread spir
On Fri, 22 Oct 2010 01:50:56 + (UTC) %u e...@ee.com wrote: What is the fastest way to fill a static multidimensional array? Looping over all dimension's elements sounds inefficient, especially as a static array is essentially continuous memory. What is the best practice? int[2][2][2

Re: [D1,static array] fill static multidimensional array.

2010-10-22 Thread Trass3r
Somehow I find it surprising that this copies the whole array. arr[] = arr2; Static arrays are value types.

[D1,static array] fill static multidimensional array.

2010-10-21 Thread %u
What is the fastest way to fill a static multidimensional array? Looping over all dimension's elements sounds inefficient, especially as a static array is essentially continuous memory. What is the best practice? int[2][2][2] arr = 0; arr[] = 3; //Error: cannot implicitly convert expression (3

Re: [D1,static array] fill static multidimensional array.

2010-10-21 Thread bearophile
%u: What is the fastest way to fill a static multidimensional array? If you want a safe solution, then you probably need nested loops, and a array[] = x; in the inner loop (such loops may be generated with a string mixin too). Otherwise if speed is more important, fixed sized multidimensional

Re: [D1,static array] fill static multidimensional array.

2010-10-21 Thread %u
== Quote from bearophile (bearophileh...@lycos.com)'s article %u: What is the fastest way to fill a static multidimensional array? If you want a safe solution, then you probably need nested loops, and a array[] = x; in the inner loop (such loops may be generated with a string mixin too