D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3402 - Please bring back canFind in std.algorithm
Summary: Please bring back canFind in std.algorithm
Status: RESOLVED WONTFIX
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: Other Windows
: P2 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-10-14 13:54 UTC by David Simcha
Modified: 2015-06-09 01:28 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description David Simcha 2009-10-14 13:54:53 UTC
Sometimes in non-performance-critical code, it's nice to be able to see whether a value is in a range in one line of code, in a straightforward way.  There is no *clean, straightforward* way to do this with std.algorithm.find.  The old std.algorithm had a canFind() function.  The canFindSorted() function was retained and I find it extremely useful for building space-efficient finite sets from arrays.  Please bring back canFind().
Comment 1 Andrei Alexandrescu 2009-10-14 18:48:33 UTC
I was hoping that find(...).empty is brief enough. Isn't it?
Comment 2 Max Samukha 2009-10-14 23:39:33 UTC
It is. But a note in the docs would be nice. An example would be enough:

// Checking if the element can be found in the range
assert(find(a, 5).empty);
Comment 3 David Simcha 2009-10-15 06:26:13 UTC
Sounds good.  I just never realized it was this easy.  I'll close this bug report.  Just please keep canFindSorted because find(assumeSorted(...)).empty is just too much typing when using an array as a space-efficient finite set.