Re: Array operations with array of structs

2015-07-11 Thread Peter via Digitalmars-d-learn
On Saturday, 11 July 2015 at 13:31:12 UTC, Peter wrote: So after looking into it a little bit... So now I'm trying to multiply the array by a double but it's giving incompatible type errors. opBinary, opBinaryRight, and opOpAssign are defined. I have: struct Vector3 { public double[3] _

Re: Array operations with array of structs

2015-07-11 Thread anonymous via Digitalmars-d-learn
On Saturday, 11 July 2015 at 13:31:12 UTC, Peter wrote: The postblit can only not take @nogc due to the array duplication which is understandable. I think the postblit might be redundant anyway since the struct is built on a static array so there is no possibility of two different Vect3s "point

Re: Array operations with array of structs

2015-07-11 Thread Peter via Digitalmars-d-learn
On Wednesday, 8 July 2015 at 06:05:54 UTC, ketmar wrote: do you see the gotcha? if you uncomment postblit or assigns, this build function fails to compile, as that operations aren't "pure nothrow @nogc @trusted", and they will be used for either assign or postblitting. So after looking into i

Re: Array operations with array of structs

2015-07-07 Thread ketmar via Digitalmars-d-learn
On Tue, 07 Jul 2015 11:09:52 +, Peter wrote: Any ideas about what's happening? yes. there is code in "arrayop.c" that tells: // Built-in array ops should be @trusted, pure, nothrow and nogc StorageClass stc = STCtrusted | STCpure | STCnothrow | STCnogc; under the hoods compile

Re: Array operations with array of structs

2015-07-07 Thread Peter via Digitalmars-d-learn
On Monday, 6 July 2015 at 15:48:28 UTC, anonymous wrote: Ok, I disabled everything in the struct except what I posted and it ran. I then uncommented stuff to isolate the cause. I've added in the bits that cause the error below (plus some constructors just for reference). struct Vector3 {

Re: Array operations with array of structs

2015-07-06 Thread anonymous via Digitalmars-d-learn
On Monday, 6 July 2015 at 12:15:22 UTC, Peter wrote: dmd 2.066.1, windows 7 64bit Tested it on Windows 7, using dmd 2.066.1: works for me. The exact code I tested (just commented those "..." out): struct Vector3 { public double[3] _p; //... Vector3 opBinary(string op)(in Vecto

Re: Array operations with array of structs

2015-07-06 Thread Peter via Digitalmars-d-learn
On Monday, 6 July 2015 at 10:29:35 UTC, anonymous wrote: Works for me with various versions of dmd on linux. What compiler are you using, what version of it, what operating system, etc? dmd 2.066.1, windows 7 64bit

Re: Array operations with array of structs

2015-07-06 Thread anonymous via Digitalmars-d-learn
On Monday, 6 July 2015 at 03:02:59 UTC, Nicholas Wilson wrote: On Monday, 6 July 2015 at 01:16:54 UTC, Peter wrote: [...] unittest{ auto a = Vector3([2.0, 2.0, 0.0]); auto b = Vector3([1.0, 2.0, 1.0]); Vector3[] c = [a]; Vector3[] d = [b]; Vector3 e = a + b; // works Vec

Re: Array operations with array of structs

2015-07-06 Thread anonymous via Digitalmars-d-learn
On Monday, 6 July 2015 at 01:16:54 UTC, Peter wrote: Hi, I have a struct with arithmetic operations defined using opBinary but array operations with arrays of it don't work. struct Vector3 { public double[3] _p; ... Vector3 opBinary(string op)(in Vector3 rhs) const if (op == "+

Re: Array operations with array of structs

2015-07-05 Thread Nicholas Wilson via Digitalmars-d-learn
On Monday, 6 July 2015 at 03:02:59 UTC, Nicholas Wilson wrote: On Monday, 6 July 2015 at 01:16:54 UTC, Peter wrote: Hi, I have a struct with arithmetic operations defined using opBinary but array operations with arrays of it don't work. struct Vector3 { public double[3] _p; ... Ve

Re: Array operations with array of structs

2015-07-05 Thread Nicholas Wilson via Digitalmars-d-learn
On Monday, 6 July 2015 at 01:16:54 UTC, Peter wrote: Hi, I have a struct with arithmetic operations defined using opBinary but array operations with arrays of it don't work. struct Vector3 { public double[3] _p; ... Vector3 opBinary(string op)(in Vector3 rhs) const if (op == "+

Array operations with array of structs

2015-07-05 Thread Peter via Digitalmars-d-learn
Hi, I have a struct with arithmetic operations defined using opBinary but array operations with arrays of it don't work. struct Vector3 { public double[3] _p; ... Vector3 opBinary(string op)(in Vector3 rhs) const if (op == "+"){ Vector3 result; result._p[] = this