Tango BitArray Initialization
sean at f4.ca
Sun Feb 11 00:28:31 PST 2007
Colin Huang wrote:
> When reading the Tango documentation, I came across this piece of code:
> import tango.core.BitArray;
> void main()
> BitArray bitbag1 = bits( 1,0,1,1,1,0 );
> // or
> BitArray bitbag2( 1,0,1,1,1,0 );
> The documentation says that "bitbag2 is initialized such that it uses a special
> opCall overload for the BitArray".
> Now the problem is that when I look at the source code, I don't see any overload
> of opCall for BitArray, or any definition for the bits function. Am I
> missing anything here?
Nope. The documentation for tango.core was the first to be written an
as a result it may be a bit inaccurate in places. It would be easy to
provide such a function however... something like this:
BitArray bits( bool mask ... )
temp.length = mask.length;
foreach( pos, val; mask )
temp[pos] = val;
It may be even better to simply make this a ctor for BitArray, so:
auto b = BitArray( 1, 0, 1, 0 );
> BTW, is the last line legal D code at all? It doesn't look like it's gonna
> compile (to me, at least).
The last line doesn't seem correct. I'll give the docs a look tomorrow.
More information about the Digitalmars-d-learn