Holes in structs and opEquals

bearophile bearophileHUGS at lycos.com
Tue Mar 9 05:18:08 PST 2010


Walter Bright:
> The non-trivial cases are not detectable (halting problem), so it is a 
> pointless feature to add.

On the other hand I have shown few ideas to avoid this problem, that require no magic abilities to a compiler, essentially making the opBinary("==") operator actively ignore the holes.

If generic code to ignore such holes is too much slow it can be a little faster creating a specialized version for each struct. If this causes too much code bloat, then the default opBinary("==") can be removed from structs and put only when the programmer asks for it with something like a @equatable property.

If a programmer wants max speed ignoring the holes, such person can define a opBinary("==") that uses memcmp or something similar.

Bye,
bearophile



More information about the Digitalmars-d mailing list