[std/array] Split staticArray overloads into two groups

It's easier to follow with the range overloads separate.
Tweak wording.
This commit is contained in:
Nick Treleaven 2023-08-11 17:13:41 +01:00 committed by The Dlang Bot
parent 41f6a45d28
commit 3a8d5018bc

View file

@ -4700,24 +4700,16 @@ unittest
} }
/++ /++
Constructs a static array from `a`. Constructs a static array from a dynamic array whose length is known at compile-time.
The type of elements can be specified implicitly so that $(D [1, 2].staticArray) results in `int[2]`, The element type can be inferred or specified explicitly:
or explicitly, e.g. $(D [1, 2].staticArray!float) returns `float[2]`.
When `a` is a range whose length is not known at compile time, the number of elements must be * $(D [1, 2].staticArray) returns `int[2]`
given as template argument (e.g. `myrange.staticArray!2`). * $(D [1, 2].staticArray!float) returns `float[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 also be specified as a
template argument to avoid having to specify the number of elements
(e.g.: `staticArray!(2.iota)` or `staticArray!(double, 2.iota)`).
Note: `staticArray` returns by value, so expressions involving large arrays may be inefficient. Note: `staticArray` returns by value, so expressions involving large arrays may be inefficient.
Params: Params:
a = The input elements. If there are less elements than the specified length of the static array, a = The input array.
the rest of it is default-initialized. If there are more than specified, the first elements
up to the specified length are used.
rangeLength = outputs the number of elements used from `a` to it. Optional.
Returns: A static array constructed from `a`. Returns: A static array constructed from `a`.
+/ +/
@ -4774,7 +4766,23 @@ nothrow pure @safe @nogc unittest
[cast(byte) 1, cast(byte) 129].staticArray.checkStaticArray!byte([1, -127]); [cast(byte) 1, cast(byte) 129].staticArray.checkStaticArray!byte([1, -127]);
} }
/// ditto /**
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)`).
Params:
a = The 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.
rangeLength = Output for the number of elements used from `a`. Optional.
*/
auto staticArray(size_t n, T)(scope T a) auto staticArray(size_t n, T)(scope T a)
if (isInputRange!T) if (isInputRange!T)
{ {