The OpenD Programming Language

BitArray.opSliceAssign

Sets the bits of a slice of BitArray starting at index start and ends at index ($D end - 1) with the values specified by val.

  1. void opSliceAssign(bool val)
  2. void opSliceAssign(bool val, size_t start, size_t end)
    struct BitArray
    @nogc pure nothrow @system
    void
    opSliceAssign
    (
    bool val
    ,
    size_t start
    ,
    size_t end
    )

Examples

import std.algorithm.comparison : equal;
import std.range : iota;
import std.stdio;

auto b = BitArray([1, 0, 0, 0, 1, 1, 0]);
b[1 .. 3] = true;
assert(b.bitsSet.equal([0, 1, 2, 4, 5]));

bool[72] bitArray;
auto b1 = BitArray(bitArray);
b1[63 .. 67] = true;
assert(b1.bitsSet.equal([63, 64, 65, 66]));
b1[63 .. 67] = false;
assert(b1.bitsSet.empty);
b1[0 .. 64] = true;
assert(b1.bitsSet.equal(iota(0, 64)));
b1[0 .. 64] = false;
assert(b1.bitsSet.empty);

bool[256] bitArray2;
auto b2 = BitArray(bitArray2);
b2[3 .. 245] = true;
assert(b2.bitsSet.equal(iota(3, 245)));
b2[3 .. 245] = false;
assert(b2.bitsSet.empty);

Meta