On Wed, 02 Feb 2011 15:55:53 +0100, spir wrote: > Hello, > > What are the default semantics for '==' on structs? > > I ask this because I was forced to write opEquals on a struct to get > expected behaviour. This struct is basically: > > struct Lexeme { > string tag; > string slice; > Ordinal index; > } > > Equal Lexeme's compare unequal using default '=='. When I add: > > const bool opEquals (ref const(Lexeme) l) { > return ( > this.tag == l.tag > && this.slice == l.slice > && this.index == l.index > ); > } > > then all works fine. What do I miss?
I think the compiler does a bitwise comparison in this case, meaning that it compares the arrays' pointers instead of their data. Related bug report: http://d.puremagic.com/issues/show_bug.cgi?id=3433 -Lars