Associative arrays in D and default comparators

Sean Kelly sean at f4.ca
Thu Sep 7 23:40:57 PDT 2006


Walter Bright wrote:
> Ivan Senji wrote:
>> Yes: here is a suggestion: remove opCmp from Object. I think the only 
>> reason it is there is that when AAs where first implemented templates 
>> weren't where they are now so there was no way to check if an object 
>> has opCmp. These days a template version of AAs would be much better, 
>> and it would (if I'm not mistaken) remove the need for opCmp to be in 
>> Object.
> 
> While it'd be fun to offer a templated version of AAs, I feel the core 
> capabilities should be available to the user without needing templates. 
> This is because many programmers are not comfortable with them.
> 
> Can you give an example of a class that could not have a meaningful 
> opCmp implementation that one would want to put into an AA?

The one I've been wrestling with is a Thread class, as it has no data 
that is static and unique for the life of the object.  The thread id is 
only guaranteed to be unique while the thread is active, and the id 
isn't even assigned until Thread.start is called.  Threads simply have 
no features which inherently support ordering, but it makes sense to 
compare two Thread objects for equality simply by comparing object 
addresses.


Sean



More information about the Digitalmars-d-bugs mailing list