BitArray new design - slice problems

Dmitry Olshansky dmitry.olsh at gmail.com
Sat Jan 19 01:07:00 PST 2013


19-Jan-2013 11:14, Era Scarecrow пишет:
> On Friday, 18 January 2013 at 16:42:04 UTC, Dmitry Olshansky wrote:
>> Slices should have a pointer and length so they can check range (in
>> debug builds), alternatively just a pointer to storage that nows the
>> range.
>
>   So write an alternate opIndex...
>
>> I think slice ops could be made @safe if the primitives for bulk
>> transfer and opIndex in the Storage are @trusted.
>>
>> If we just mark all of opSlice on Fixed-sized one as @system then it
>> should be good enough. In other words (I'm lost in terminology):
>>
>
> <snip>
>
>> The idea is to make code responsible for the "root" of unsafety to be
>> @system everything else then can be @safe or @trusted(where compiler
>> can't see it).
>
>   Hmmm okay... Somehow this seemed so much more complex than it's put here.
>
>> I think that the most of slice ops can be @safe/@trusted. It's the
>> process of taking a slice out of stack-based container that is not
>> @safe. The one taking a slice out of GC-based one is @safe.
>
>   And depending on if it is fixed or dynamic will determine if the slice
> is @system or @safe... Makes sense. That sets me straight.
>
>
>   So for the slice/range, what all should it support? I've tried to have
> it support (or foward) opBinary, opBinaryAssign, comparing, slicing,
> copying, as well as inputRange, bidirectional, opIndex & opIndex assign,
> opDollar and length. If it should support a much smaller sub-set I'll
> need to know; Could greatly affect how it is written.


opBinaryAssign --> opOpAssign. opSlice/opSlice assign.
In any case it seems to me that (I think you already did this trick 
before) you can reuse a lot of code by making an operator string a 
template parameter (for functions that implement  =, |=, &=, ^=, and 
therefore ^, |, &) and use string mixins.

Other then this - don't forget the '~' _unary_ operator as it makes a 
lot of sense for bit-vectors. Now since slices don't support '~' 
concatenation it won't look so bad. Worst case:

auto ba = BitArray(...);
auopt slice = ba[...];
ba ~= ~slice;

And it's not much of problem.
-- 
Dmitry Olshansky


More information about the Digitalmars-d-learn mailing list