[Issue 323] New: Error: need opCmp for class Bar

xs0 xs0 at xs0.com
Thu Sep 7 10:41:59 PDT 2006


Sean Kelly wrote:
> Since D's associative arrays use opCmp to resolve collisions, any class 
> that has opEquals defined should probably have opCmp defined also.  The 
> old default implementation of Object.opCmp in Phobos was not compatible 
> with compacting GCs so it was replaced with a version that throws an 
> exception on use.  However, there is a default implementation that 
> actually works and is compatible with compacting GCs:
> 
>     int opCmp(Object o)
>     {
>     return this !is o;
>     }

That's not a really good solution, as no usable ordering is defined (a>b 
and b>a will always be true whenever a !is b). While it may work for 
(degenerate) insertion into a binary tree, it's (imho) worse than 
throwing an exception in practically all other cases. For example, a 
quick sort will not only run really slow in O(n^2) time but also produce 
an unsorted result without any indication of error.


xs0



More information about the Digitalmars-d-bugs mailing list