recursive equal, and firstDifference functions

Dan dbdavidson at yahoo.com
Tue Mar 19 19:48:38 PDT 2013


On Wednesday, 20 March 2013 at 02:03:31 UTC, Jonathan M Davis 
wrote:
> We already get this. That's what == does by default. It's just 
> that it uses ==
> on each member, so if == doesn't work for a particular member 
> variable and the
> semantics you want for == on the type it's in, you need to 
> override opEquals.

Really?

string is one most people would like == to just work for. This 
writes true then false. This certainly takes getting used to. It 
alone is a good reason for the mixins and potentially a 
non-member instancesDeepEqual.

import std.stdio;
struct S {
   string s;
}
void main() {
   writeln("foo" == "foo".idup);
   writeln(S("foo") == S("foo".idup));
}




More information about the Digitalmars-d-learn mailing list