Comment #0 by iamthewilsonator — 2015-07-06T03:25:15Z
see http://forum.dlang.org/thread/[email protected]
currently dmd says
Error: invalid array operation 'expression' because type doesn't support necessary arithmetic operations.
Enhance to tell user which operations (opSlice / opSliceAssign etc.) they need to implement to get desired behaviour.
Comment #1 by nick — 2023-07-05T15:35:18Z
The problem seems to be that `f` does not have length 1:
> Vector3[] f;
When that is fixed, it works:
struct Vector3 {
public double[3] arr;
Vector3 opBinary(string op)(in Vector3 rhs) const
if (op == "+") {
Vector3 result;
result.arr[] = this.arr[] + rhs.arr[];
return result;
}
}
unittest {
auto a = Vector3([2.0, 2.0, 0.0]);
auto b = Vector3([1.0, 2.0, 1.0]);
Vector3 e = a + b; // works
Vector3[] c = [a];
Vector3[] d = [b];
Vector3[1] f;
f[] = c[] + d[]; // works
}
Also I can't reproduce the original error with all the compilers on run.dlang.io , maybe they don't go back that far.
Comment #2 by robert.schadek — 2024-12-13T18:43:42Z