On Mon, 23 Aug 2010 22:49:14 -0400, bearophile <[email protected]> wrote:

This a part of std.bitmanip.BitArray:


    void init(void[] v, size_t numbits)
    in
    {
        assert(numbits <= v.length * 8);
        assert((v.length & 3) == 0);
    }
    body
    {
        ptr = cast(uint*)v.ptr;
        len = numbits;
    }


But it seems this program works with no errors:

import std.bitmanip: BitArray;
void main() {
    ubyte[4] data;
    BitArray bits;
    bits.init(data, 100);
}

If bitarray is not a template, then it's compiled in release mode inside phobos. The in contract is probably not compiled in.

Do you kno why is this assert present?
assert((v.length & 3) == 0);

Isn't this enough?
assert((v.length & 2) == 0);

The first is asserting that v.length is a multiple of 4, I think the point is to be able to manipulate all the data using words. Yours is asserting, well, it's asserting that the second bit is not set. That yields the following sequence:

0,1,4,5,8,9,12,13...

I'm not sure why you want that sequence.

-Steve

Reply via email to