On Saturday, 13 October 2012 at 22:19:44 UTC, H. S. Teoh wrote:
Wait, there's such a thing as overloading 'is'? If there is,
that's pretty messed up. The 'is' operator is used for a lot of
fundamental stuff, and allowing structs and classes to change
that just sounds ... wrong.
Sure there is, it's just not one you can override to my
knowledge (along with in (AA & array) I believe). I only referred
to it as opIs since that's likely how internally the compiler
deals with it, plus there's a reference to opIs in 2008.
On Saturday, 13 October 2012 at 22:42:35 UTC, bearophile wrote:
"is" is meant to perform a bitwise comparison (I think today it
is working as designed or it's very close to this target).
So on class references "is" performs a bitwise comparison of
the references themselves.
On values (like structs) "is" compares the struct values
bit-wise.
In your code x1 and x2 contain the same bit patterns (32 bits
set to zero), so "x1 is x2" is true.
TDPL pg. 57
[quote]
The expression a is b compares for alias equality and returns
true if a and be refer to the same actual object.
* If a and b are arrays or class references, the result is true
if and only if a and b are two named for the same actual object.
* Otherwise, a is b is the same as a == b
[/quote]
Hmm I had more the impression it was address space only. But if
it's in the manual and spec, then I'm wrong and just needed a
refresher on it. Course if structs are relocatable and are
identical, they are as good as the same object.
So *shrugs* Sorry for bringing it up then.