Tango BitArray Initialization

John Reimer terminal.node at gmail.com
Sun Feb 11 22:27:30 PST 2007


On Sun, 11 Feb 2007 19:41:48 -0800, Sean Kelly wrote:

> Colin Huang wrote:
>> John Reimer Wrote:
>> 
>>> (The last line could be legal if an opCall were implemented.)
>> 
>> Even if an opCall overload were in place, I doubt that the last line would
>  > compile. It certainly didn't last time I tried (I'm using gdc 0.22 on 
> Windows).
>> I may be wrong on this, of course.
>> 
>> In fact, I've been wanting to be able to do that for quite some time now, so I
>  > can use structs like stack-allocated objects in C++ (syntax-wise, at
>> least).   If it actually works, pls give some examples. thx
> 
> I don't think this is legal in D.  In fact, the syntax is a huge problem 
> in C++ because the parser often can't distinguish between a variable 
> decl and a function prototype, and function prototypes take precedence. 
>   It may be uglier, but:
> 
>      BitArray b = BitArray( 1, 0, 1 );
> 
> is better than:
> 
>      BitArray b( 1, 0, 1 );
> 
> I only wish that the syntax worked for all stack variables.  ie.
> 
>      int x = int( 1 );
> 
> 
> Sean


Apparently I missed the issue completely, Sorry.  I'm not sure how or why
I came up with the notation in the first place.  

What I'm actually interested in seeing is a simple solution here for
assignment of a binary type.

Another simple alternative could employ a static opAssign.

This would make things much simpler:

BitArray bitbag = 0b11111000000;

The value is limited to 64-bits, but at least it's clean and simple for
those situations where we don't have a long initialization value.
(this would work for hexidecimal value also).  For any larger values we
can use an array literal assignment or something similar.

-JJR


More information about the Digitalmars-d-learn mailing list