Prevent self-comparison without taking the address

Dom DiSc dominikus at scherkl.de
Thu Jul 25 10:50:04 UTC 2024


I have copied some source from C++, where the following pattern 
is common (operator== already renamed):

```d
@safe:
struct S
{
    bool opEquals(const ref S x) const
    {
       if(&x==&this) return true;
       ...
    }
}
```

Can I replace this pattern with ```(x is this)``` or are there 
some special cases where this doen't work?


More information about the Digitalmars-d-learn mailing list