Find out what type my class is being converted to for comparisons
ag0aep6g
anonymous at example.com
Tue Oct 18 20:02:02 UTC 2022
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;
}
}
```
More information about the Digitalmars-d-learn
mailing list