Struct Comparison

dsimcha dsimcha at yahoo.com
Thu Oct 22 07:39:53 PDT 2009


== Quote from Andrei Alexandrescu (SeeWebsiteForEmail at erdani.org)'s article
> > 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.
> This can be done if you associate a cost with each operation (e.g.
> comparing numbers has cost 1, comparing strings has cost 10, comparing
> using a user-defined function has cost 40 etc.) and then optimize for
> smallest average cost.
> Andrei

Right, this is what I had in mind.  I take it this isn't a common, well-known
optimization technique already?  Walter?



More information about the Digitalmars-d mailing list