digitalmars.D - opEquals need to change
- Lars Ivar Igesund (25/25) Feb 14 2007 The Tango project received a bug report today, about an int that couldn'...
The Tango project received a bug report today, about an int that couldn't be implicitly converted to a bool. The offending function is a template function like this bool equals ( T p1, T p2 ) { return p1 == p2; } Now, the user had this module instantiated with Object, thus the return statement becomes ((cast(Object)(p1)).opEquals)(cast(Object)(p2)) and since int no longer are implicitly convertible to bools (very correct decision to disallow this btw), this operation will fail. It works just fine with T like any base type though. This appears to be a very glaring flaw and outright error in Object, and claiming that this is more efficient is nothing but premature optimization as using a bool should be eminently optimizable on modern processors. The link to a page showing the timing of an instruction (used by GCC afaik?) that should handle this bool graciously (mentioned several times in the past). http://www.cs.tut.fi/~siponen/upros/intel/instr/sete_setz.html -- Lars Ivar Igesund blog at http://larsivi.net DSource & #D: larsivi Dancing the Tango
Feb 14 2007