Method for initialising an array of structs
Chris Nicholson-Sauls
ibisbasenji at gmail.com
Mon Jan 15 20:53:37 PST 2007
Chris Williams wrote:
> 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
This might make potential sense as a new addition to ArrayOps, one of the features
deferred to "2.0". It means being able to do things like (array1[] += array2[]) so its in
roughly the same ballpark. I know I wouldn't mind having it. (It'd make things like
delegate arrays rather nifty as well... (array[](foo, bar);).)
-- Chris Nicholson-Sauls
More information about the Digitalmars-d-learn
mailing list