Associative Arrays

Carlos Santander csantander619 at gmail.com
Fri Mar 16 08:50:17 PDT 2007


Dan escribió:
> Walter, what's happening with them?
> 
> Last I checked, I couldn't use practically anything of them:
> 
> const char[] TEXT_x = "x";
> int[char[]] x;
> 
> x.length = 1; // doesn't work, no property length
> x["hello"] = 1; // doesn't work, array out of bounds
> x[TEXT_x] = 1; // doesn't work, array out of bounds
> 
> Also, there was a drowned out call by some folks to get static associative arrays.
> 
> What would be the primary blocker for that?  The use of pointers for hashing?
> 
> Is it possible to use opIndex etc to override associatives?

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.

-- 
Carlos Santander Bernal



More information about the Digitalmars-d mailing list