staticArray

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

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.

Examples

static array from CT range

import std.range : iota;

enum a = staticArray!(2.iota);
static assert(is(typeof(a) == int[2]));
assert(a == [0, 1]);

enum b = staticArray!(long, 2.iota);
static assert(is(typeof(b) == long[2]));
assert(b == [0, 1]);

static array from range + size

import std.range : iota;

auto input = 3.iota;
auto a = input.staticArray!2;
static assert(is(typeof(a) == int[2]));
assert(a == [0, 1]);
auto b = input.staticArray!(long[4]);
static assert(is(typeof(b) == long[4]));
assert(b == [0, 1, 2, 0]);

Meta