On Tuesday, 18 October 2022 at 20:02:02 UTC, ag0aep6g wrote:
On Tuesday, 18 October 2022 at 18:53:41 UTC, Matthew Rushworth wrote:
The entirety of opEquals:

```
/// both matrices have to have an identical shape to compare
/// each element must be identical to match
bool opEquals(size_t X, size_t Y)(const Matrix!(X,Y) m1, const Matrix!(X,Y) m2) { for (int i = 0; i < m1.data.length; ++i) if (m1.data[i] != m2.data[i]) return false;
    return true;
}
```

A free-standing opEquals won't work. It needs to be a method of the class. So:

```d
class Matrix(size_t X, size_t Y = X)
{
    /* ... */

    bool opEquals(const Matrix m2)
    {
        for (int i = 0; i < this.data.length; ++i)
            if (this.data[i] != m2.data[i]) return false;
        return true;
    }
}
```

Thank you, that worked perfectly, not sure exactly what I did wrong, I'm assuming I forgot to make the parameter a const variable

Reply via email to