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
    Vector3[] f;
f[] = c[] + d[]; // Error: invalid array operation 'f[] = c[] + d[]' because Vector3 doesn't support necessary arithmetic operations
}

how can I get this to work?

Thanks

you need to define the slice operators. e.g.

auto opSlice() // no parameters to get whole slice eg. a[]
// can also define with opSlice(size_t i, size_t j)
                      // for access like a[ i .. j]
{
    return _p;
}

`f`, `c`, and `d` are arrays though, not `Vector3`s. The code doesn't try to slice a Vector3. So as far as I can see, there's no point in adding opSlice to it.

Reply via email to