Fix Issue 17679 - SortedRange.contains should be deprecated in favor of the generic canFind#5651
Fix Issue 17679 - SortedRange.contains should be deprecated in favor of the generic canFind#5651wilzbach wants to merge 1 commit intodlang:masterfrom
Conversation
…of the generic canFind
| assert(r1.release() == [ 64, 52, 42, 3, 2, 1 ]); | ||
| } | ||
|
|
||
| deprecated |
There was a problem hiding this comment.
I duplicated the relevant unittest, s.t. we continue to test contains
| $(RED Deprecated - please use $(REF canFind, std,algorithm.searching) instead). | ||
| */ | ||
| // @@@DEPRECATED_2018-02@@@ | ||
| deprecated("Please use std.algorithm.searching : canFind instead.") |
There was a problem hiding this comment.
@jmdavis - I hope I have done it correctly this time?
IIRC the stages were:
- mark in documentation as deprecated
- remove from documentation
- remove entirely
|
Should canFind be aliased/renamed to contains? It's more general naming. |
|
The apparent duplication is intentional and useful. |
|
@andralex But canFind specializes for SortedRange, so there's no speed benefit to using one over the other. |
|
That's an opportunistic optimization. Calling canFind means "I don't care whether this is linear, just find the thing". It's nice to have that use contains if available. |
Yep copy/pasting from Bugzilla:
|
|
@wilzbach the usefulness of the distinction is in generic code that wants to make sure fast searching is available |
Isn't it the opposite for generic code? It should only care about the static if(isSortedRange!(Range, pred)
// faster path
else
// normal pathand not at the call site: static if (hasMember!(Range, "contains"))
r.contains(42);
else
r.canFind(42);Anyway I don't care about this too strongly. I just found on the NG that people struggle with it and find it confusing. |
|
Offering functions of distinct complexity is within the doctrine of generic programming; there's long established practice of such in the STL, viz. member vs. non-member The Achilles's heel of checking for |
|
@wilzbach Since Andrei has a good argument in favor and there's been no activity on this, I'm closing this. Please reopen if you have a counter point. |
See also: http://forum.dlang.org/post/sjwsaofnanozytrvwxpb@forum.dlang.org