BitArray contracts

bearophile bearophileHUGS at lycos.com
Tue Aug 24 08:25:25 PDT 2010


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

I see, it's the problem discussed recently, with the proposal of the two phobos libs, one compiled with -release and one without, that the compiler chooses according to the type of your compilation.


> 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.

You are right, I was very wrong (to avoid such errors I use the modulus % for that purpose, the compiler optimizes it away).
But CPU words may be 8 bytes long too, so in that code I prefer:
assert(v.length % size_t.sizeof == 0);

Bye and thank you,
bearophile


More information about the Digitalmars-d-learn mailing list