finding composed structs

Ali Çehreli acehreli at yahoo.com
Tue Oct 30 09:44:02 PDT 2012


On 10/30/2012 08:26 AM, 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

There is the following discussion currently on the main D forum:

   http://forum.dlang.org/thread/iphhuttpkogmfwpuvfla@forum.dlang.org

That behavior will be changed:

 
http://forum.dlang.org/thread/iphhuttpkogmfwpuvfla@forum.dlang.org?page=4#post-k6a30m:24140h:241:40digitalmars.com

Ali



More information about the Digitalmars-d-learn mailing list