recursive equal, and firstDifference functions

Jonathan M Davis jmdavisProg at gmx.com
Tue Mar 19 03:08:25 PDT 2013


On Tuesday, March 19, 2013 09:25:43 timotheecour wrote:
> we need a std.algorithm.equalRecurse(T1,T2)(T1 a, T2 b) that
> compares recursively a and b;
> 
> its behavior should be:
> 
> if opEqual is defined, call it
> else, if its a range, call std.algorithm.equal (ie compare nb
> elements, then each element for equality)
> else, if it's a class/struct, make sure types are same and call
> it recursively on each field.
> else if it's a numerical type, call "=="
> else (is there an else?)
> 
> just as std.algorithm.equal, we should have
> equalRecurse([1],[1.0]);

If you want recursive equal, then do equal!equal. Granted, that's only one 
level of recursion, but how many levels deep are you really going to have your 
ranges? And you have to get to == eventually anyway in order to compare the 
deepest elements. Going beyond a range of ranges is likely to be quite rare, 
and when it does happen, you can simply nest equal as many times as you need.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list