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
    void
    opSliceAssign
    (
    bool val
    ,
    size_t start
    ,
    size_t end
    )

Examples

1 import std.algorithm.comparison : equal;
2 import std.range : iota;
3 import std.stdio;
4 
5 auto b = BitArray([1, 0, 0, 0, 1, 1, 0]);
6 b[1 .. 3] = true;
7 assert(b.bitsSet.equal([0, 1, 2, 4, 5]));
8 
9 bool[72] bitArray;
10 auto b1 = BitArray(bitArray);
11 b1[63 .. 67] = true;
12 assert(b1.bitsSet.equal([63, 64, 65, 66]));
13 b1[63 .. 67] = false;
14 assert(b1.bitsSet.empty);
15 b1[0 .. 64] = true;
16 assert(b1.bitsSet.equal(iota(0, 64)));
17 b1[0 .. 64] = false;
18 assert(b1.bitsSet.empty);
19 
20 bool[256] bitArray2;
21 auto b2 = BitArray(bitArray2);
22 b2[3 .. 245] = true;
23 assert(b2.bitsSet.equal(iota(3, 245)));
24 b2[3 .. 245] = false;
25 assert(b2.bitsSet.empty);

Meta

Suggestion Box / Bug Report