initializedArray
Andrej Mitrovic
andrej.mitrovich at gmail.com
Tue Dec 20 04:55:08 PST 2011
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