staticArray

fnT[n] staticArray(T, size_t n)(auto ref T[n] a)

Constructs a static array from a dynamic array whose length is known at compile-time. The element type can be inferred or specified explicitly:

[1, 2].staticArray returns int[2] [1, 2].staticArray!float returns float[2]

Note

staticArray returns by value, so expressions involving large arrays may be inefficient.

Parameters

aThe input array.

Returns

A static array constructed from a.
fnU[n] staticArray(U, T, size_t n)(auto ref T[n] a) if (!is(T == U) && is(T : U))

ditto

fnauto staticArray(size_t n, T)(scope T a) if (isInputRange!T)

Constructs a static array from a range. When a.length is not known at compile time, the number of elements must be given as a template argument (e.g. myrange.staticArray!2). Size and type can be combined, if the source range elements are implicitly convertible to the requested element type (eg: 2.iota.staticArray!(long[2])).

When the range a is known at compile time, it can be given as a template argument to avoid having to specify the number of elements (e.g.: staticArray!(2.iota) or staticArray!(double, 2.iota)).

Parameters

aThe input range. If there are less elements than the specified length of the static array, the rest of it is default-initialized. If there are more than specified, the first elements up to the specified length are used.
rangeLengthOutput for the number of elements used from a. Optional.
fnauto staticArray(size_t n, T)(scope T a, out size_t rangeLength) if (isInputRange!T)

ditto

fnauto staticArray(Un : U[n], U, size_t n, T)(scope T a) if (isInputRange!T && is(ElementType!T : U))

ditto

fnauto staticArray(Un : U[n], U, size_t n, T)(scope T a, out size_t rangeLength) if (isInputRange!T && is(ElementType!T : U))

ditto

fnauto staticArray(alias a)() if (isInputRange!(typeof(a)))

ditto

fnauto staticArray(U, alias a)() if (isInputRange!(typeof(a)))

ditto