"is" operator for structures?

Steven Schveighoffer schveiguy at yahoo.com
Wed May 9 09:45:49 PDT 2012


On Wed, 09 May 2012 12:17:30 -0400, Gor Gyolchanyan  
<gor.f.gyolchanyan at gmail.com> wrote:

> I didn't know structs actually have an "is" operator. Good to know,
> there's a way to memcmp them this way.
> But being able to overload it wouldn't do any damage. The overloader
> of "is" should clearly know, that "is" is an identity check and not an
> arbitrary domain-specific equality check.
> Overloading "is" gives a syntax sugar for nullable structures and an
> optimization opportunity for large ones (for example a CRC checksum
> comparison).

The fact that it's not overloadable is useful in many situations.  There  
are certain cases you are truly looking for physical equality, and not  
logical equality.

Generally, if you want logical equality, use opEquals.

-Steve


More information about the Digitalmars-d mailing list