// compile with: dmd vector.d -inline -O -release -w -g // debug with: windbg vector.exe import std.stdio; import std.string; struct Vector3(T) { T x, y, z; string toString() { return "(" ~ format("%g", x) ~ " " ~ format("%g", y) ~ " " ~ format("%g", z) ~ ")"; } void opAddAssign(Vector3 v) { x += v.x; y += v.y; z += v.z; } Vector3 opMul(T s) { return Vector3(x * s, y * s, z * s); } } alias Vector3!(float) Vector3f; int main(char[][] args) { Vector3f v1 = {1.0f, 2.0f, 3.0f}; Vector3f v2 = {4.0f, 5.0f, 6.0f}; writefln(v1, " ", v2); // first v1 += v2 * 3.0f; // second v1.x += v2.x * 3.0f; v1.y += v2.y * 3.0f; v1.z += v2.z * 3.0f; writefln(v1, " ", v2); return 0; }