www.digitalmars.com         C & C++   DMDScript  

D - D dynamic array initialization

reply "Dan Liebgold" <dliebgold yahoo.com> writes:
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
Mar 10 2003
parent "Walter" <walter digitalmars.com> writes:
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
Mar 13 2003