BitArray.opBinary

Support for binary bitwise operators for BitArray.

  1. BitArray opBinary(BitArray e2)
    struct BitArray
    const pure nothrow
    opBinary
    (
    string op
    )
    (
    const BitArray e2
    )
    if (
    op == "-" ||
    op == "&"
    ||
    op == "|"
    ||
    op == "^"
    )
  2. BitArray opBinary(bool b)
  3. BitArray opBinary(BitArray b)

Examples

static bool[] ba = [1,0,1,0,1];
static bool[] bb = [1,0,1,1,0];

auto a = BitArray(ba);
auto b = BitArray(bb);

BitArray c = a & b;

assert(c[0] == 1);
assert(c[1] == 0);
assert(c[2] == 1);
assert(c[3] == 0);
assert(c[4] == 0);
bool[] ba = [1,0,1,0,1];
bool[] bb = [1,0,1,1,0];

auto a = BitArray(ba);
auto b = BitArray(bb);

BitArray c = a | b;

assert(c[0] == 1);
assert(c[1] == 0);
assert(c[2] == 1);
assert(c[3] == 1);
assert(c[4] == 1);
bool[] ba = [1,0,1,0,1];
bool[] bb = [1,0,1,1,0];

auto a = BitArray(ba);
auto b = BitArray(bb);

BitArray c = a ^ b;

assert(c[0] == 0);
assert(c[1] == 0);
assert(c[2] == 0);
assert(c[3] == 1);
assert(c[4] == 1);
bool[] ba = [1,0,1,0,1];
bool[] bb = [1,0,1,1,0];

auto a = BitArray(ba);
auto b = BitArray(bb);

BitArray c = a - b;

assert(c[0] == 0);
assert(c[1] == 0);
assert(c[2] == 0);
assert(c[3] == 0);
assert(c[4] == 1);

Meta