March 11, 2003 D dynamic array initialization | ||||
---|---|---|---|---|
| ||||
D should allow dynamic arrays to be initialized like static arrays, and with dynamic initializers as well. For example: void test (float max) { float table[] = [ max*0.25, max*0.5, max*0.75, max ]; } And also for associative arrays: void test2 () { int maptable[char[]] = [ "hello":0, "world":1, "\n":2 ]; } Perhaps the expression "[1,2,3]" could create a dynamic array in place, and assignment would copy it. This would enable expressions like: void func (char [] name, float[] table) { ... } void test3 () { func("stuff", [1.2, 2.4, 4.8]); } Dan |
March 13, 2003 Re: D dynamic array initialization | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dan Liebgold | Yes, those are good ideas. "Dan Liebgold" <dliebgold@yahoo.com> wrote in message news:b4k3bm$h9j$1@digitaldaemon.com... > D should allow dynamic arrays to be initialized like static arrays, and with > dynamic initializers as well. For example: > > void test (float max) { > float table[] = [ max*0.25, max*0.5, max*0.75, max ]; > } > > And also for associative arrays: > > void test2 () { > int maptable[char[]] = [ "hello":0, "world":1, "\n":2 ]; > } > > Perhaps the expression "[1,2,3]" could create a dynamic array in place, and > assignment would copy it. This would enable expressions like: > > void func (char [] name, float[] table) { ... } > void test3 () { > func("stuff", [1.2, 2.4, 4.8]); > } > > Dan > > |
Copyright © 1999-2021 by the D Language Foundation