Thanks,
Actually I'm realizing there's a lot I'm unclear about when it comes to default comparison, equality, hashing, etc.

If my struct contains a dynamic array, are the contents of the array compared by default, or just the pointers/lengths?

Also, when two arrays are compared for content, are their pointers compared first in case they happen to be the same so the deep comparison can be shortcut? Also, how do I obtain the default hash of a dynamic array ('s contents)? Is there one? I assume there must be since associative arrays can take string as a key-type.

To make a struct a valid key type, do I need to implement both opCmp and opEquals or just one or the other. It says on the page about Associative Arrays: "The implementation may use either opEquals or opCmp or both." Does that mean it uses whichever one is user-defined (or both if they're both user-defined)? Or does it mean the user is responsible for defining both?

Also, it says "Care should be taken so that the results of opEquals and opCmp are consistent with each other when the struct/union objects are the same or not.", certainly this means that if a.opEquals(b), then a.opCmp(b) should be 0, but does the converse have to be true?

Is there somewhere I can find information about default operator implementations and consistency?

Reply via email to