ArrayBoundsError for associative array operation
xs0
xs0 at xs0.com
Tue Dec 5 04:05:31 PST 2006
Egor Starostin wrote:
> I have a testcase (simplified from real data) when access to
> associative array by existing key produces ArrayBoundsError.
>
> Here it is:
> ***
> [snip]
> ***
>
> Why I get an ArrayBoundsError for existing key?
> Is this a bug in D? If yes -- can somebody suggest a workaround?
>
Most likely you forgot to implement a function or two:
http://www.digitalmars.com/d/arrays.html#associative
Structs or unions can be used as the KeyType. For this to work, the
struct or union definition must define the following member functions:
* hash_t toHash()
* int opEquals(S) or int opEquals(S*)
* int opCmp(S) or int opCmp(S*)
Note that the parameter to opCmp and opEquals can be either the struct
or union type, or a pointer to the struct or untion type.
xs0
More information about the Digitalmars-d
mailing list