BitArray/BitFields - Review

Dmitry Olshansky dmitry.olsh at gmail.com
Sun Jul 29 02:03:07 PDT 2012


On 29-Jul-12 12:55, Era Scarecrow wrote:
> On Sunday, 29 July 2012 at 06:27:32 UTC, Dmitry Olshansky wrote:
>> Thus BitArray either becomes value type (that may come as unexpected,
>> see your option c/d). Or it becomes full reference type as in option a
>> (though it sucks). Sorry but b is no go, as it makes code
>> unpredictable I'd rather take my idea with separate ranges then b.
>
>   I've had a thought. Why not make it fully reference and at the same
> time not? Consider making a slice which is the real BitArray, then you
> have an outer container that when you want value semantics you use it
> and it would make appropriate copies every time it needed to (including
> when first put in the container). It would be implicitly convertible to
> a slice. So...
>
> BitArraySlice {
>    //real bitarray stuff and pointer ref
> }
>
> BitArray { //value semantics wrapper?
>    BitArraySlice ba;
>    alias ba this;
>
>    //include wrapper versions of binary operators
>
>    this(this) {
>    }
> }
>
>   Doing it this way the arguments being passed as reference slices would
> ensure unneeded copies wouldn't be made. On the other hand a smaller
> portion of the code would need to be updated. Along with that a slice
> could be set as COW allowing quite a bit of flexibility.
>
>   Thoughts?

Hm... and small array optimizations go where? BitArraySlice won't be a 
full reference type if it does it.

-- 
Dmitry Olshansky


More information about the Digitalmars-d-learn mailing list