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

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 delegate

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 [1],

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 othe

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, w

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 Is there anything better for this? I mean, the program will fill the array with zeroes, just to overwrite all of them with -1. That's wasted execution time a

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 Is there anything better for this? I mean, the program will fill the array with zeroes, just to overwrite all of them with -1. That's wasted execution time and doesn't feel D-ish

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 compile

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 Is there an

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 Is there anything better for this? I mean, the program will fill the array with zeroes, just to overwrite all of them with -1. That's wasted execution time and doesn't feel D-ish to me.

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 becau

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"; } I

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: arra

Re: Length of Dimension in Multidimensional Array?

2015-06-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/5/15 3:53 AM, Ralf the Bat wrote: Probably a stupid question, but how do I find the length of each dimension in a multidimensional array? if you mean a static array, you can get each dimension using .length: int[2][3] arr; static assert(arr.length == 3); static assert(arr[0].length == 2

Re: Length of Dimension in Multidimensional Array?

2015-06-05 Thread Dennis Ritchie via Digitalmars-d-learn
On Friday, 5 June 2015 at 07:53:52 UTC, Ralf the Bat wrote: Probably a stupid question, but how do I find the length of each dimension in a multidimensional array? I slightly modified the function deepDup, who came up Ali Çehreli :) http://beta.forum.dlang.org/post/mihl6m$1che$1

Length of Dimension in Multidimensional Array?

2015-06-05 Thread Ralf the Bat via Digitalmars-d-learn
Probably a stupid question, but how do I find the length of each dimension in a multidimensional array?

Re: multidimensional array

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

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 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 array of n instances of > type T

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" 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 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 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. You can

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 wrote: > > > struct Spot { bool dot; } > > spots = new Spot[][](800,600); > btw, does anybody know why i can do `new ubyte[256];` but not > `new ubyt

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

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 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 signature

Re: multidimensional array

2014-09-27 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[]

multidimensional array

2014-09-27 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-27 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 bou

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 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 ?

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

2014-01-28 Thread bearophile
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; Where a std.range.flatten should take a range, range of ranges, range of range of ranges, etc, and yield the ite

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

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

2014-01-28 Thread Gary Willoughby
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!("a[0][1] == b[1][1]").array; The above is my attempt and it failed.

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 r

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:18 PM, seany wrote: > I See that in stack exchange, that it is possible to create > multidimensional arrays like : > > [][] 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 w

Multidimensional array in d2?

2013-11-14 Thread seany
I See that in stack exchange, that it is possible to create multidimensional arrays like : [][] 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 multidimensiona

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

Re: Multidimensional array

2013-07-05 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-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 c

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 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 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 or

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 = "xx"d; string s2 = "xx"w; wstring s3 = "xx"d; } Bye, bearophile Also, don't forget the often forgotten explicit c suffix: ds

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, be

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 i

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 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 defi

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 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 acce

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: dc

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 m

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 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
y to copy all the values from one multidimensional array to another.

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

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 some

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 kn

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 p

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 kn

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 a

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 mul

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: `matrix.byTopDimension[x].byTopDimension[y].byTopDimension

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, y

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 th

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 th

Re: Fixed size multidimensional array at runtime

2012-06-30 Thread Denis Shelomovskij
rrect. 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 i

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 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 mig

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 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 i

Re: Fixed size multidimensional array at runtime

2012-06-30 Thread Jonathan M Davis
correct me if my assumptions 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 pag

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

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

2010-10-22 Thread %u
== Quote from spir (denis.s...@gmail.com)'s article > How does this method perform? would you be kind enough to include it in you > r tests, %u? Even if it's slightly slower than "(cast(int[n1*n2*n3])arr)[] > = e;", I would use it because I find it cleaner. But it does take up more memory (assumin

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.

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

2010-10-22 Thread spir
On Fri, 22 Oct 2010 01:50:56 + (UTC) %u 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? &

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 wit

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 si

[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 expressi