Vector.this

Constructs a Vector with elements from an Input Range. Values not provided by range are initialized to 0, while additional values are ignored.

  1. this(T scalar)
  2. this(T[N] values)
  3. this(R range)
    struct Vector(T, uint N)
    this
    (
    R
    )
    (
    auto ref R range
    )
    if (
    isInputRange!R
    )
    if (
    N > 0
    )
  4. this(U value)
  5. this(Args args)

Examples

float[] values = [1, 2];
assert(Vec4(values) == [1, 2, 0, 0]);

import std.range : iota, stride;
assert(Vec4(iota(4)) == [0, 1, 2, 3]);
assert(Vec4(iota(8).stride(2)) == [0, 2, 4, 6]);
assert(Vec4(iota(6)) == [0, 1, 2, 3]);

import std.algorithm : map;
auto isEven = iota(1024).map!(x => x % 2 == 0);
assert(Vec4bool(isEven) == [true, false, true, false]);

Meta