Thread overview
AA with class keys compared with identity instead of opEquals
Sep 27, 2020
Per Nordlöw
Sep 27, 2020
Ferhat Kurtulmuş
Sep 27, 2020
Per Nordlöw
Sep 27, 2020
Per Nordlöw
Sep 27, 2020
Ferhat Kurtulmuş
Sep 28, 2020
Per Nordlöw
Sep 28, 2020
Per Nordlöw
September 27, 2020
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*`?
September 27, 2020
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.


September 27, 2020
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.
September 27, 2020
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
September 27, 2020
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.
September 28, 2020
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.
September 28, 2020
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.