Vector.opBinary

Returns a new vector with binary operator applied to all elements and scalar

  1. Vector opBinary(T scalar)
  2. auto opBinary(U scalar)
    struct Vector(T, uint N)
    pure const
    opBinary
    (
    string op
    U
    )
    (
    const U scalar
    )
    if (
    !is(U : T) &&
    !is(CommonType!(U, T) == void)
    &&
    !op.among("~", "<<", ">>", ">>>")
    )
    if (
    N > 0
    )
  3. Vector!(T, max(N, M)) opBinary(T[M] other)
  4. Vector!(CommonType!(U, T), max(N, M)) opBinary(U[M] other)
  5. Vector!(T, N + 1) opBinary(T scalar)
  6. Vector!(T, N + M) opBinary(T[M] other)

Examples

Vec2 a = [1, 2];
assert(a + 1 == [1f + 1f, 2f + 1f]);
assert(a - 1 == [1f - 1f, 2f - 1f]);
assert(a * 2 == [1f * 2f, 2f * 2f]);
assert(a / 2 == [1f / 2f, 2f / 2f]);
assert(a % 2 == [1f % 2f, 2f % 2f]);
assert(a ^^ 2 == [1f ^^ 2f, 2f ^^ 2f]);

Vec2i b = [1, 2];
assert((b & 1) == [1 & 1, 2 & 1]);
assert((b | 1) == [1 | 1, 2 | 1]);
assert((b ^ 1) == [1 ^ 1, 2 ^ 1]);

Meta