Array operations with array of structs

anonymous via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jul 6 08:48:27 PDT 2015


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 Vector3 rhs) const
     if (op == "+"){
         Vector3 result;
         result._p[] = this._p[] + rhs._p[];
         return result;
     }
     //...
}

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;
     Vector3[] f;
     f[] = c[] + d[];
}
----

And the command line: dmd -main -unittest test.d


More information about the Digitalmars-d-learn mailing list