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?