El 26/03/2012 13:58, bearophile escribió:
Issue 3789 is an enhancement request, I think it fixes one small but quite 
important problem in D design. The situation is shown by this simple code:


struct String {
     char[] data;
}
void main () {
     auto foo = String("foo".dup);
     auto bar = String("foo".dup);
     assert(bar !is foo, "structs aren't the same bit-wise");
     assert(bar == foo, "oops structs aren't equal");
}



The D Zen says D is designed to be safe on default and to perform unsafe (and 
faster) things on request. Not comparing the strings as strings in the 
following code breaks the Principle of least astonishment, so breaks that rule.



Maybe it makes more sense that struct==struct applies == to each of its fields. It would be the same as bitwise comparison for simple primitive types, but would be more useful with other types such as strings.

Reply via email to