StaticBitArray.opApply

Support for foreach loops for StaticBitArray.

  1. int opApply(int delegate(ref bool) dg)
  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)
    struct StaticBitArray(uint capacity, Block = DefaultBlock)
    @safe const @trusted
    int
    opApply
    (
    scope int delegate
    (
    size_t
    ,
    bool
    )
    dg
    )
    if (
    isUnsigned!DefaultBlock
    )

Examples

static bool[] ba = [1,0,1];
auto a = StaticBitArray!3(ba);
size_t i;
foreach (immutable b; a[]) // TODO is `opSlice` the right thing?
{
    switch (i)
    {
    case 0: assert(b == true); break;
    case 1: assert(b == false); break;
    case 2: assert(b == true); break;
    default: assert(0);
    }
    i++;
}
foreach (j, b; a)       // TODO is `opSlice` the right thing?
{
    switch (j)
    {
    case 0: assert(b == true); break;
    case 1: assert(b == false); break;
    case 2: assert(b == true); break;
    default: assert(0);
    }
}

Meta