finding composed structs

Tobias Pankrath tobias at pankrath.net
Tue Oct 30 09:11:20 PDT 2012


On Tuesday, 30 October 2012 at 15:26:22 UTC, Dan wrote:
> Please help me with any flaws in logic or understanding:
>
> For any struct S, '==' means either bitwise comparison or a 
> call to opEquals of S if it exists.
> If S has no (dynamic arrays, associative arrays, pointers, or 
> class references as members (recursively)) then bitwise compare 
> is equivalent to a deep compare.
>
> But if you do have any of those and you want true deep 
> comparison semantics, you must implement a correct opEquals at 
> the first introduction of those members, and carry that forward 
> through all composed structures to S.
>
> struct A { int x = 3; }
> struct B { A a; }
> struct C { B b; }
> struct D { C c; }
>
> So in this case, D has deep equality semantics for ==.
> But change A to struct A { string x; } and the deep equality 
> semantics for D disappears. To get it back an opEquals must be 
> correctly implemented in A, B, C, and D.
>
> Is this accurate?
> If true and not an issue, people must not be relying too much 
> on deep equality semantics like this. But how else can you find 
> things?
>
> Thanks
> Dan

You are correct. But I argue and I think TDPL says the same, that 
== should compare all members and is should bitwise compare. 
However that is currently not the case.


More information about the Digitalmars-d-learn mailing list