Tango BitArray Initialization

Sean Kelly sean at f4.ca
Tue Feb 13 12:02:51 PST 2007


Thomas Brix Larsen wrote:
> Sean Kelly wrote:
> 
>> Colin Huang wrote:
>>> Sean Kelly Wrote:
>>>
>>>> Oddly, I wasn't able to get static opAssign to work with this syntax.
>>>> It seemed to want "BitArray = 0" rather than "BitArray b = 0".  I've
>>>> modified Tango's BitArray to support:
>>>>
>>>>      BitArray b = [0,1,0,1];
>>>>      b = [1,0,1,0];
>>>>
>>>> which is consistent with how built-in arrays work.
>>>>
>>>>
>>>> Sean
>>> Good work :)
>> By the way, I think the above will break when implicit type conversions
>> are added, because [0,1,0,1] is currently passed as a bool[].  I'll need
>> to think about this a bit more, since [true,false,true,false] kind of
>> stinks, as does accepting an array of ubyte or some such.  This is an
>> issue Walter will have to face as well since Phobos BitArray will have
>> the same problem.
>>
>>
>> Sean
> 
> Can't you just make it a ubyte array, and throw an error if it isn't filled
> with ones and zeros?
> 
> Something like:
> if(...
>    throw new Error("Stupid human! Bits are made up of ones and zeros!!");

Yup, and this is what will probably happen.


Sean


More information about the Digitalmars-d-learn mailing list