On Tuesday, November 20, 2012 23:46:39 Namespace wrote: > Something like: > scope int[8] arr; > or > scope int[i] arr; > > would be cool. You get an resizeable array which capactiy is all > the time equal to his length. And it is destroyed after the > liftetime of the scope. > > Maybe some stuff for Remus...
It's pretty trivial to create a struct which uses malloc and free to create a dynamic array of the exact size that you want with deterministic destruction, and you can easily overload the indexing and slicing operators - though clearly, as if with static arrays, you'd have to be careful with slices being passed around, since they're not owned by the GC. And I'm not sure what would happen if you were foolish enough to try and append to them. Personally though, I wish that the length of static arrays could be set at runtime and don't really understand why you can't (aside from the fact that you can't in standard C - gcc will let you though). - Jonathan M Davis