The OpenD Programming Language

BitArray.this

Creates a BitArray from a bool array, such that bool values read from left to right correspond to subsequent bits in the BitArray.

  1. this(bool[] ba)
    struct BitArray
    nothrow pure
    this
    (
    in bool[] ba
    )
  2. this(void[] v, size_t numbits)

Examples

import std.algorithm.comparison : equal;

bool[] input = [true, false, false, true, true];
auto a = BitArray(input);
assert(a.length == 5);
assert(a.bitsSet.equal([0, 3, 4]));

// This also works because an implicit cast to bool[] occurs for this array.
auto b = BitArray([0, 0, 1]);
assert(b.length == 3);
assert(b.bitsSet.equal([2]));
import std.algorithm.comparison : equal;
import std.array : array;
import std.range : iota, repeat;

BitArray a = true.repeat(70).array;
assert(a.length == 70);
assert(a.bitsSet.equal(iota(0, 70)));

Meta