StaticBitArray.opApply

Support for foreach loops for StaticBitArray.

  1. int opApply(int delegate(ref bool) dg)
    struct StaticBitArray(uint capacity, Block = DefaultBlock)
    @safe @trusted
    int
    opApply
    (
    scope int delegate
    (
    ref bool
    )
    dg
    )
    if (
    isUnsigned!DefaultBlock
    )
  2. int opApply(int delegate(bool) dg)
  3. int opApply(int delegate(const ref size_t, ref bool) dg)
  4. int opApply(int delegate(size_t, bool) dg)

Examples

1 static bool[] ba = [1,0,1];
2 auto a = StaticBitArray!3(ba);
3 size_t i;
4 foreach (immutable b; a[]) // TODO is `opSlice` the right thing?
5 {
6     switch (i)
7     {
8     case 0: assert(b == true); break;
9     case 1: assert(b == false); break;
10     case 2: assert(b == true); break;
11     default: assert(0);
12     }
13     i++;
14 }
15 foreach (j, b; a)       // TODO is `opSlice` the right thing?
16 {
17     switch (j)
18     {
19     case 0: assert(b == true); break;
20     case 1: assert(b == false); break;
21     case 2: assert(b == true); break;
22     default: assert(0);
23     }
24 }

Meta