Re: Array operations, dynamic arrays and length

2015-07-04 Thread jmh530 via Digitalmars-d-learn
On Thursday, 2 July 2015 at 19:27:57 UTC, J Miller wrote: I knew that automatic allocation doesn't happen, but I'm confused by the fact if you explicitly declare "c" with "int[] c;" and then assign "c[] = a[] * b[]", versus using "auto c = a[] * b[]", you get two different errors (array length

Re: Array operations, dynamic arrays and length

2015-07-02 Thread J Miller via Digitalmars-d-learn
On Thursday, 2 July 2015 at 12:59:03 UTC, Steven Schveighoffer wrote: On 7/2/15 8:21 AM, "Marc =?UTF-8?B?U2Now7x0eiI=?= " wrote: On Thursday, 2 July 2015 at 10:48:56 UTC, Steven Schveighoffer wrote: On 7/1/15 8:36 PM, J Miller wrote: Oh, and to make things really confusing, "auto e = a[] - b[

Re: Array operations, dynamic arrays and length

2015-07-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/2/15 8:21 AM, "Marc =?UTF-8?B?U2Now7x0eiI=?= " wrote: On Thursday, 2 July 2015 at 10:48:56 UTC, Steven Schveighoffer wrote: On 7/1/15 8:36 PM, J Miller wrote: Oh, and to make things really confusing, "auto e = a[] - b[]" and "int[] e = a[] - b[]" both cause "Error: array operation a[] - b

Re: Array operations, dynamic arrays and length

2015-07-02 Thread via Digitalmars-d-learn
https://issues.dlang.org/show_bug.cgi?id=14759

Re: Array operations, dynamic arrays and length

2015-07-02 Thread via Digitalmars-d-learn
On Thursday, 2 July 2015 at 10:48:56 UTC, Steven Schveighoffer wrote: On 7/1/15 8:36 PM, J Miller wrote: Oh, and to make things really confusing, "auto e = a[] - b[]" and "int[] e = a[] - b[]" both cause "Error: array operation a[] - b[] without destination memory not allowed". Using dmd 2.0

Re: Array operations, dynamic arrays and length

2015-07-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/1/15 8:36 PM, J Miller wrote: Oh, and to make things really confusing, "auto e = a[] - b[]" and "int[] e = a[] - b[]" both cause "Error: array operation a[] - b[] without destination memory not allowed". Using dmd 2.067.0. This is not a bug. You need to allocate memory before you can wri

Re: Array operations, dynamic arrays and length

2015-07-01 Thread J Miller via Digitalmars-d-learn
On Wednesday, 1 July 2015 at 21:15:13 UTC, Marc Schütz wrote: On Wednesday, 1 July 2015 at 19:09:36 UTC, Alex Parrill wrote: I don't think this is a bug. Since you don't initialize `c` to anything, it defaults to an empty slice. Array [] operations apply to each element of a slice, but `c` do

Re: Array operations, dynamic arrays and length

2015-07-01 Thread via Digitalmars-d-learn
On Wednesday, 1 July 2015 at 19:09:36 UTC, Alex Parrill wrote: I don't think this is a bug. Since you don't initialize `c` to anything, it defaults to an empty slice. Array [] operations apply to each element of a slice, but `c` doesn't have any elements, so it does nothing. I _do_ think it'

Re: Array operations, dynamic arrays and length

2015-07-01 Thread Alex Parrill via Digitalmars-d-learn
On Tuesday, 30 June 2015 at 22:37:34 UTC, ixid wrote: int[] a = [1,1,1,1]; int[] b = [1,1,1,1]; int[] c; c[] = a[] - b[]; c.writeln; This outputs []. This feels wrong, it feels like something that should have exploded or set the length to 4. If the leng

Re: Array operations, dynamic arrays and length

2015-07-01 Thread via Digitalmars-d-learn
On Tuesday, 30 June 2015 at 22:37:34 UTC, ixid wrote: int[] a = [1,1,1,1]; int[] b = [1,1,1,1]; int[] c; c[] = a[] - b[]; c.writeln; This outputs []. This feels wrong, it feels like something that should have exploded or set the length to 4. If the leng

Array operations, dynamic arrays and length

2015-06-30 Thread ixid via Digitalmars-d-learn
int[] a = [1,1,1,1]; int[] b = [1,1,1,1]; int[] c; c[] = a[] - b[]; c.writeln; This outputs []. This feels wrong, it feels like something that should have exploded or set the length to 4. If the lengths of a and b are mismatched it throws an exception.