digitalmars.D - allocate an array of AA?
- sa (12/12) Mar 08 2008 How to allocate an array of AA?
- bearophile (4/7) Mar 08 2008 It's a bug of DMD. I think you have to use a loop with a creation follow...
- sa (7/12) Mar 08 2008 append (~=) to the array.
- bearophile (19/20) Mar 08 2008 I think some sugar can be added to the language for this. In the meantim...
How to allocate an array of AA? I tried two ways (new, and setting array length), in both cases the code compiles, but the executable seems run into infinite loop, and never finish. void allocAA() { int[int][] maps; maps = new int[int][3]; maps.length = 3; } int main() { allocAA(); return 0; }
Mar 08 2008
sa Wrote:How to allocate an array of AA? I tried two ways (new, and setting array length), in both cases the code compiles, but the executable seems run into infinite loop, and never finish.It's a bug of DMD. I think you have to use a loop with a creation followed by an append (~=) to the array. Bye, bearophile
Mar 08 2008
== Quote from bearophile (bearophileHUGS lycos.com)'s articlesa Wrote:append (~=) to the array. But how to write such 'a creation'? i.e. how to new an AA? what's the syntax? tried: int[int]* mapsp; mapsp = new int[int]; // this line The compiler complains: need size of rightmost array, not type intHow to allocate an array of AA? I tried two ways (new, and setting array length), in both cases the code compiles, but the executable seems run into infinite loop, and never finish.It's a bug of DMD. I think you have to use a loop with a creation followed by an
Mar 08 2008
sa:But how to write such 'a creation'? i.e. how to new an AA? what's the syntax?I think some sugar can be added to the language for this. In the meantime you can use this from my D libs: /*************************************** Return a new empty associative array of the given KeyType,ValueType. Example: AA!(int, string); */ template AA(KeyType, ValueType) { const ValueType[KeyType] AA = AA_impl!(KeyType, ValueType).res; } private template AA_impl(KeyType, ValueType) { ValueType[KeyType] result; const ValueType[KeyType] res = result; } to be used as something as: aaa char[int][]; foreach(_; xrange(10)) aaa ~= AA!(int, char); Bye, bearophile
Mar 08 2008