BitArray/BitFields - Reworking with templates

Era Scarecrow rtcvb32 at yahoo.com
Mon Jul 30 14:03:37 PDT 2012


On Monday, 30 July 2012 at 20:19:51 UTC, Dmitry Olshansky wrote:
> Not sure what you would like to accomplish here.

Than an example...

struct BitArray { //assume template...
   ref BitArray opSliceAssign(T)(const T ba, int start, int end)
   if (
    //if T is type bitArray but only a different change regarding 
parameters
    //we can use canUseBulk and other speedups. Otherwise a range 
is required.
    //checking all possibilities seems silly, but possible
   )
   body {
     //slice specific speedup and code
     return this;
   }
   int opEquals(T)(const T ba) const
   //if constraint as above
   body {}
}

Code wise; If BitSet is always value semantics and BitArray is 
always reference (a previous post) and slices/groups work 
basically the same; then...

BitSet bs = BitSet(100);
BitArray ba = BitArray(100);

  bs[0 .. 10] = ba[0 .. 10]; //should work
  assert(bs[0 .. 10] == ba[0 .. 10]); //should also be possible to 
work.

>> alias X!(true).XY Xtrue;
>>
>> pure function 'func' cannot call impure function '__cpctor'
>> safe function 'func' cannot call system function '__cpctor'
>
> Yeah, it's a bug. File it please.

Alright... Considered a major (Maybe even blocking).

  Reminds me. Due to how rvalue/lvalues work, assuming I need to 
const reference something but I don't care if it's a temporary or 
not, would I then do...

struct X {
   int opCmp(const X x) const { //catch temporary
     return opCmp(x); //becomes reference, as it's now named 'x'
   }
   int opCmp(const ref X x) const {
     //do work here
     return 0;
   }
}

X x;
assert(x == x);   //ref
assert(x == X()); //temporary

  course if the 'in' keyword is the key i will have to test that 
to make sure.


More information about the Digitalmars-d-learn mailing list