recursive equal, and firstDifference functions

timotheecour timothee.cour2 at gmail.com
Tue Mar 19 13:13:21 PDT 2013


> That's opEquals' job. It deals with recursive comparisons like 
> you're describing here just fine.

Except the functionality is very different, as opEquals is blind 
to range semantics. I want equalRecurse to work as follows:

struct A{	int[]b=[1]; }

void main(){
	auto a1=A();
	auto a2=A();
	assert(a1!=a2); //opEquals says it's different
	assert(equalRecurse(a1,a2)); //equalRecurse says it's the same
	// assert(equal(a1,a2)); //equal doesn't compile, only works for 
ranges.
}



> There's no reason to define that externallly to the type.

Yes there is: it can be done automagically to work on vast 
majority of cases (see what several ppl have posted), and it 
avoids overly redundant boilerplate code. In my example here, I 
don't want to redefine an opEquals to make the "assert(a1==a2);" 
above pass, because:
-it's boilerplate
-equalRecurse has different semantics anyways
-meaning of equalRecurse should be clear to anyone.




More information about the Digitalmars-d-learn mailing list