Associative Arrays

Dan murpsoft at hotmail.com
Fri Mar 16 11:49:15 PDT 2007


Carlos Santander Wrote:

> What exactly are you doing? This compiles and runs successfully with GDC 0.23, 
> and should be the same with DMD (unless something is broken with 1.009):
> 
> void main ()
> {
>      const char[] TEXT_x = "x";
>      int[char[]] x;
> 
>      //x.length = 1;
>      x["hello"] = 1;
>      x[TEXT_x] = 1;
> }
> 
> And yeah, AAs don't have length. You can get their length with x.keys.length, 
> but you can't set it.

Okay, thanks Carlos.  I'll have to run the simplified test case, but for Walnut, I couldn't use a Value[char[]] in any of the ways described (Value is a struct).  I could declare the associative arrays and handle them, but not populate the associative array with anything or set the length.

I thought associative arrays might not be dynamic because it was giving me an Array out of bounds exception when I tried to assign to it.

~~~

Regarding the opIndex, what I meant was perhaps being able to, for example, define an override for line two of:

1 ||  int[char[]] x;
2 || x["hello"] = 0;

It's not clear in documentation whether you can or not, only that you can do it with int's - one would assume in static or dynamic arrays.





More information about the Digitalmars-d mailing list