Bug 17679 – SortedRange.contains should be deprecated in favor of the generic canFind

Status
RESOLVED
Resolution
INVALID
Severity
enhancement
Priority
P4
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2017-07-24T20:23:57Z
Last change time
2023-11-27T12:12:25Z
Assigned to
No Owner
Creator
Seb

Comments

Comment #0 by greensunny12 — 2017-07-24T20:23:57Z
Since https://github.com/dlang/phobos/pull/4907, find takes advantage of Sortedness: https://github.com/dlang/phobos/blob/57b8d2511ea37cd01665b9b663d8ba246144b1f9/std/algorithm/searching.d#L1509 Hence, there's no need for the confusing `contains` method and it should be deprecated in favor of `canFind`. See also: http://forum.dlang.org/post/[email protected]
Comment #1 by nick — 2023-11-27T12:12:25Z
Closing as having both is intentional. Generic code may need `contains` to guarantee complexity. The alternative: > The Achilles's heel of checking for SortedRange is that not only sorted ranges have fast contains - a variety of hashed containers come to mind. Any range with fast searching should implement contains. Discussion starts here: https://github.com/dlang/phobos/pull/5651#issuecomment-317558570