Fawzi Mohamed:

>I am not sure of what is the best solution,<

This is true for me too, that's why I have created this thread, to find a way 
to solve this problem.


>I am not sure that defining a special comparison operation by default for each 
>struct is the correct solution (it can be quite some bloat), please note that 
>a user defined comparison function will not have these problems.<

Note that if you write a opEquals for each struct then you have the same code 
bloat. The difference is that you have had to write lot of boring code, that 
can contain bugs, and your program is longer.

In a program you don't use == and != (or hashing) on all the structs, so in 
theory the compiler can add such opEquals only to the structs that are tested 
for equality in the program. I guess the usual modular compilation requirement 
of D code asks too all structs to have such opEquals. In this case the 
Link-Time Optimization of LLVM comes to the rescue and removed unused functions 
from the whole program/whole compilation block.

Another possible solution is to have a single opEquals in the runtime, that 
works like the array sort, using run time knowledge about the types. But this 
is of probably slower.

Bye,
bearophile

Reply via email to