Phobos uses opSlice and opDollar without checking for it

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Wed May 25 09:21:07 PDT 2016


On Wed, May 25, 2016 at 03:05:33PM +0000, qznc via Digitalmars-d wrote:
> Today I learned [0] that opDollar must be explicitly implemented and
> might not be available by some ranges. Likewise slicing. If you think
> it further, there are lots of functions in Phobos (I'm currently
> looking into std.algorithm.searching) which use more features than
> they check capabilities for. Ranges which satisfy isRandomAccessRange
> do not automatically satisfy hasSlicing.

These are bugs. Please file them and fix them.


> Can we provide opSlice and opDollar implicitly for random access
> ranges?

Perhaps... though this would be a breaking change for existing random
access ranges that don't implement opSlice/opDollar.


> Alternatively, we should comb through Phobos to fix the capability
> checks and write unittests with minimalistic ranges.
> 
> I already filed issue 16073 [1], but then realized it does not go far
> enough.
> 
> Also, std.range.primitives should have a predicate for opDollar
> similar to hasSlicing.

It's hard to imagine having much use for a range that has slicing but
not opDollar.  For simplicity's sake, I'd suggest keeping the two
together. Since we already have hasSlicing, I'd say put the check for
opDollar in hasSlicing.


T

-- 
People tell me I'm stubborn, but I refuse to accept it!


More information about the Digitalmars-d mailing list