Bug 19637 – Add a pre-condition to "in" and contains()
Status
RESOLVED
Resolution
INVALID
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-01-31T22:57:52Z
Last change time
2019-01-31T23:36:50Z
Assigned to
No Owner
Creator
Victor Porton
Comments
Comment #0 by porton — 2019-01-31T22:57:52Z
Accordingly https://dlang.org/phobos/std_range.html "in" and contains() require sorted range.
Please add pre-condition to check if it is really sorted.
This will help to locate subtle errors.
Comment #1 by sascha.orlov — 2019-01-31T23:29:26Z
Arent't "in" and contains already properties of a SortedRange object? How comes that your SortedRange is not sorted?
According to
https://dlang.org/phobos/std_algorithm_sorting.html#.isSorted
the check for sortedness would require O(r.length) evaluations. I don't think, you really want to have this check run every evaluation of "in" or contains, do you?
Comment #2 by porton — 2019-01-31T23:36:50Z
I have not noticed that contains() is a member of SortedRange.
So, you are right, I am closing the bug.