Re: AA with class keys compared with identity instead of opEquals

2020-09-28 Thread Per Nordlöw via Digitalmars-d-learn

On Monday, 28 September 2020 at 08:26:15 UTC, Per Nordlöw wrote:
In the case where the AA-KeyType is a class (which is 
represented as a pointer in D) I want the equality (opEquals) 
and the hashing (toHash) of the AA to compare and hash the 
pointers themselves, not the fields the classes points to.


For D-classes this is the default. For extern(C++) classes it's 
not defined. That's why I added the struct wrapper on top of an 
extern(C++) class.


Re: AA with class keys compared with identity instead of opEquals

2020-09-28 Thread Per Nordlöw via Digitalmars-d-learn
On Sunday, 27 September 2020 at 19:45:07 UTC, Ferhat Kurtulmuş 
wrote:
Sorry I did not understand what you meant. It would be better 
if you share the answer here. I found this also 
https://dlang.org/library/std/traits/key_type.html, but I dont 
know if it is related.


In the case where the AA-KeyType is a class (which is represented 
as a pointer in D) I want the equality (opEquals) and the hashing 
(toHash) of the AA to compare and hash the pointers themselves, 
not the fields the classes points to.


Re: AA with class keys compared with identity instead of opEquals

2020-09-27 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Sunday, 27 September 2020 at 19:37:10 UTC, Per Nordlöw wrote:

On Sunday, 27 September 2020 at 18:39:10 UTC, Per Nordlöw wrote:
How do I defined an AA with class as key where keys are 
compared using `is` instead of `opEquals`? Do I have to store 
the key as a `void*`?


I got a good answer at 
https://dlang.slack.com/archives/C1ZDHBB2S/p1601234030016700


Sorry I did not understand what you meant. It would be better if 
you share the answer here. I found this also 
https://dlang.org/library/std/traits/key_type.html, but I dont 
know if it is related.


Re: AA with class keys compared with identity instead of opEquals

2020-09-27 Thread Per Nordlöw via Digitalmars-d-learn

On Sunday, 27 September 2020 at 18:39:10 UTC, Per Nordlöw wrote:
How do I defined an AA with class as key where keys are 
compared using `is` instead of `opEquals`? Do I have to store 
the key as a `void*`?


I got a good answer at 
https://dlang.slack.com/archives/C1ZDHBB2S/p1601234030016700


Re: AA with class keys compared with identity instead of opEquals

2020-09-27 Thread Per Nordlöw via Digitalmars-d-learn
On Sunday, 27 September 2020 at 18:56:15 UTC, Ferhat Kurtulmuş 
wrote:
By looking at object.d and aaA.d of druntime, I d say you don't 
need to use void*. Object class has required infrastructure 
ready for using classes aa keys (have not tried though). Object 
class has both toHash and opEquals already implemented.


That's gonna be much slower. And I need key's to be checked for 
equivalence ,not equality.


Re: AA with class keys compared with identity instead of opEquals

2020-09-27 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Sunday, 27 September 2020 at 18:39:10 UTC, Per Nordlöw wrote:
How do I defined an AA with class as key where keys are 
compared using `is` instead of `opEquals`? Do I have to store 
the key as a `void*`?


By looking at object.d and aaA.d of druntime, I d say you don't 
need to use void*. Object class has required infrastructure ready 
for using classes aa keys (have not tried though). Object class 
has both toHash and opEquals already implemented.





AA with class keys compared with identity instead of opEquals

2020-09-27 Thread Per Nordlöw via Digitalmars-d-learn
How do I defined an AA with class as key where keys are compared 
using `is` instead of `opEquals`? Do I have to store the key as a 
`void*`?