digitalmars.D.learn - multidimensional array
- Joel (5/5) Sep 27 2014 I'm trying to make a multidimensional array. I feel I've tried
- JKPdouble (16/21) Sep 27 2014 dot is initialized to false, then the assertion fails. But your
- JKPdouble (10/32) Sep 27 2014 I meant:
- Joel (2/2) Sep 29 2014 Thanks JKPdouble. I was hoping for a clear way to work
- ketmar via Digitalmars-d-learn (4/6) Sep 28 2014 btw, does anybody know why i can do `new ubyte[256];` but not
- Stewart Gordon (8/14) Sep 28 2014 You can do `new ubyte[256][256]`, if the destination type is a ubyte[256...
- ketmar via Digitalmars-d-learn (8/12) Sep 28 2014 On Sun, 28 Sep 2014 22:33:40 +0100
- Stefan Frijters (5/10) Sep 28 2014 You could also take a look at unstd.multidimarray (not my work,
- H. S. Teoh via Digitalmars-d-learn (5/12) Sep 28 2014 File a bug.
- ketmar via Digitalmars-d-learn (4/5) Sep 28 2014 On Sun, 28 Sep 2014 07:40:23 -0700
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");
Sep 27 2014
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 is initialized to false, then the assertion fails. But your assertion message leads to think that there is a bound error, which is not the case, the assertion fails because you're expecting dot to be true: ---- import std.stdio; void main(string args[]) { struct Spot { bool dot; } auto spots = new Spot[][](800,600); writeln(spots); assert(!spots[800-1][600-1].dot, "Out of bounds"); } ---- passes without failure. Actually the array size is OK.
Sep 27 2014
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 meant: ---- void main(string args[]) { struct Spot { bool dot; } auto spots = new Spot[][](800,600); assert(!spots[800-1][600-1].dot, "element dot is true"); } ----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 is initialized to false, then the assertion fails. But your assertion message leads to think that there is a bound error, which is not the case, the assertion fails because you're expecting dot to be true: ---- import std.stdio; void main(string args[]) { struct Spot { bool dot; } auto spots = new Spot[][](800,600); writeln(spots); assert(!spots[800-1][600-1].dot, "Out of bounds"); } ---- passes without failure. Actually the array size is OK.
Sep 27 2014
Thanks JKPdouble. I was hoping for a clear way to work multidimensional arrays out.
Sep 29 2014
On Sun, 28 Sep 2014 04:24:19 +0000 Joel via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:struct Spot { bool dot; } spots =3D new Spot[][](800,600);btw, does anybody know why i can do `new ubyte[256];` but not `new ubyte[256][256];`? hate that.
Sep 28 2014
On 28/09/2014 08:48, ketmar via Digitalmars-d-learn wrote:On Sun, 28 Sep 2014 04:24:19 +0000 Joel 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 array of n instances of type T. In this case, T is ubyte[256], which is a static array type. Stewart. -- My email address is valid but not my primary mailbox and not checked regularly. Please keep replies on the 'group where everybody may benefit.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.
Sep 28 2014
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 array of n instances of type T. In this case, T is ubyte[256], which is a static array type.it's completely counterintuitive. either `new ubyte[256];` should be disallowed, or `new ubyte[256][256];` should work as i expect it to work. it's the same thing as with const methods: `const A foo ()`. yes, 'const' is a method attribute here, but it's counterintuitive.
Sep 28 2014
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 could also take a look at unstd.multidimarray (not my work, but I'm using it extensively at the moment)[1]. [1] http://denis-sh.bitbucket.org/unstandard/unstd.multidimarray.html
Sep 28 2014
On Sun, Sep 28, 2014 at 10:48:45AM +0300, ketmar via Digitalmars-d-learn wrote:On Sun, 28 Sep 2014 04:24:19 +0000 Joel via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:File a bug. T -- I see that you JS got Bach.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.
Sep 28 2014
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=3D13556
Sep 28 2014