Method for initialising an array of structs

Chris Williams chris at c2cube.com
Mon Jan 15 18:46:49 PST 2007


D allows you to do something like:

uint[3] temp;
temp[] = 42;

Thus allowing you to set the initial state without having to write a loop.
Going from this, it seems like you should be able to do something like:

struct Test {
  uint a;
}
Test[3] temp;
temp[].a = 42;

Or:

temp[] = {
 a : 42
}

But neither of these seem to work. Is there a method for doing this?

If not then I guess I would like to offer this as an addition to the language
following from the existing syntax. It seems like you should be able to do it,
given the way an array of a basic type can be handled.

Thank you,
Chris


More information about the Digitalmars-d-learn mailing list