"is" operator for structures?

Gor Gyolchanyan gor.f.gyolchanyan at gmail.com
Wed May 9 09:17:30 PDT 2012


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).

On Wed, May 9, 2012 at 8:13 PM, Steven Schveighoffer
<schveiguy at yahoo.com> wrote:
> On Wed, 09 May 2012 10:13:01 -0400, bearophile <bearophileHUGS at lycos.com>
> wrote:
>
>> Gor Gyolchanyan:
>>
>>> Because the opBinary [...]
>>
>>
>> Thank for your answer, but I don't carte of "why" the D compiler accepts
>> that. I only care about the D compiler statically refusing that.
>
>
> This also works too:
>
> int opBinary(string s: "booya!")(...)
>
> or this too:
>
> int opBinry(string s: "+")(...)
>
> opBinary is a valid symbol, and as a valid symbol, it is a valid function,
> no matter whether the compiler calls it in a special way.
>
> I don't think it is a terrible thing, and I think statically disallowing
> that would be a worse idea.
>
> And to answer the OP, 'is' is special, it signals a bitwise compare, no
> matter what the contents of the type being compared.
>
> That being said, I understand why you want to do that.  I don't see any way
> around it.
>
> -Steve



-- 
Bye,
Gor Gyolchanyan.


More information about the Digitalmars-d mailing list