Struct Comparison

Don nospam at nospam.com
Thu Oct 22 07:36:48 PDT 2009


dsimcha wrote:
> Regarding recent discussions in Bugzilla:  I wonder if we could somehow define
> a super-efficient struct opEquals that performs introspection and only tests
> expensive members if it's necessary.

The compiler should be doing this. It's the way to fix the Bugzilla bug.
There should be no need to define opEquals() unless it does something 
different to an element-by-element comparison.

> Of course, we could get even fancier.  We could recursively introspect struct
> types and use various heuristics to calculate the optimal comparison order at
> compile time.  Similar stuff could be done for a generic opCmp that gives a
> struct an arbitrary total ordering as long as all of its members have a total
> ordering.

Yes. This is something the compiler can't (or shouldn't) do.



More information about the Digitalmars-d mailing list