initializedArray

Paul D. Anderson paul.d.removethis.anderson at comcast.andthis.net
Tue Dec 20 10:02:42 PST 2011


I think this is a great idea and a good example of adding to the 
library rather than changing the syntax.

Paul

"Wouldn't the sentence 'I want to put a hyphen between the words 
Fish and And and And and Chips in my Fish-And-Chips sign' have 
been clearer if quotation marks had been placed before Fish, and 
between Fish and and, and and and And, and And and and, and and 
and And, and And and and, and and and Chips, as well as after 
Chips?" — Martin Gardner

On Tuesday, 20 December 2011 at 12:55:18 UTC, Andrej Mitrovic 
wrote:
> I think it would be cool to have an initializedArray function, 
> which
> creates and initializes an array with a *specific* initializer. 
> A
> hardcoded example would be:
>
> import std.array;
>
> auto initializedArray(F:float[])(size_t size, float init)
> {
>   auto arr = uninitializedArray!(float[])(size);
>   arr[] = init;
>   return arr;
> }
>
> void main()
> {
>   float[] arr = initializedArray!(float[])(3, 0.0f);
>   assert(arr[] == [0.0f, 0.0f, 0.0f]);
> }
>
> Currently there's no D syntax for using new on arrays and 
> specifying a
> specific initializer, so maybe we should have this as a library
> function. Thoughts?




More information about the Digitalmars-d mailing list