Simple array init question
Graham
grahamamacdonald at gmail.com
Sat Apr 7 12:52:17 PDT 2007
The 1st is what I went for. Not being able to initialise a
multidimensional array using the same syntax as a one dimensional array
seems a bit inconsistent - either a bug or an omission - so I figured
I'd mention it here.
Thanks.
Chris Nicholson-Sauls wrote:
> In which case you've got two immediate options, and a third option
> requiring a library. :)
>
> Immediate #1 - Use a loop (possibly wrapped in a function) to init the
> array.
>
> Immediate #2 - Use a typedef of the array's element type with a custom
> init value -- unfortunately this is rarely realistic as typedef types
> are strong in D.
>
> Library option - Use Cashew (cashew.utils.Array) thusly:
> int[1024][1024] buf = repeat(repeat(5, 1024_U), 1024_U);
>
> (Admittedly untested, but it should work fine. Cashew is available from
> DSource.)
> http://www.dsource.org/projects/cashew
>
>
> When it comes right down to it, I actually have to admit to wishing the
> '[][] = 5' approach worked. Hm.
>
> -- Chris Nicholson-Sauls
More information about the Digitalmars-d
mailing list