Bug 3402 – Please bring back canFind in std.algorithm
Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2009-10-14T13:54:00Z
Last change time
2015-06-09T01:28:30Z
Assigned to
nobody
Creator
dsimcha
Comments
Comment #0 by dsimcha — 2009-10-14T13:54:53Z
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 by andrei — 2009-10-14T18:48:33Z
I was hoping that find(...).empty is brief enough. Isn't it?
Comment #2 by samukha — 2009-10-14T23:39:33Z
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 by dsimcha — 2009-10-15T06:26:13Z
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.