Comment #1 by peter.alexander.au — 2013-09-23T13:52:29Z
What's the bug? Neither range contains the other, so canFind returns false.
Comment #2 by alienballance — 2013-09-23T14:43:30Z
I'm sorry for reporting false bug-report then.
size_t canFind(alias pred = "a == b", Range, Ranges...)(Range haystack, Ranges needles);
It's "Ranges" and not "Range" as i've seen, and:
"if used directly in the condition of an if statement or loop, the result will be true if one of the needles is found and false if none are found"
just looked like "find the first index of needle from Range of needles".
Comment #3 by monarchdodra — 2013-09-23T23:30:25Z
(In reply to comment #2)
> I'm sorry for reporting false bug-report then.
>
> size_t canFind(alias pred = "a == b", Range, Ranges...)(Range haystack, Ranges
> needles);
>
> It's "Ranges" and not "Range" as i've seen, and:
>
> "if used directly in the condition of an if statement or loop, the result will
> be true if one of the needles is found and false if none are found"
>
> just looked like "find the first index of needle from Range of needles".
I think it's worth noting that "Ranges..." is a gratuitious limitation, as the function would perfectly support "Needles". EG: If you unlock the restraint, than this work for me:
assert([1, 2, 3].canFind(5, [1, 2, 3], 2) == 3);
I renamed the bug report, it should be fixed.
--------
In your original use case though, I don't think we have any version of find that accepts a variable amount of needles (which is what you were asking for?).
Comment #4 by dlang-bot — 2023-11-06T13:02:20Z
@ntrel created dlang/phobos pull request #8845 "Fix Issue 11111 - std.algorithm.canFind should support Needles..." fixing this issue:
- Fix Issue 11111 - std.algorithm.canFind should support Needles...
The requirement that each needle must be a range is arbitrary, so remove
it.
Note: This overload of `canFind` calls `find(haystack, needles)` which
calls `startsWith`, which accepts mixed element and range needles.
https://github.com/dlang/phobos/pull/8845
Comment #5 by nick — 2023-11-06T13:02:58Z
> I don't think we have any version of find that accepts a variable amount of needles
dlang.org/phobos/std_algorithm_searching.html#findAmong
Comment #6 by dlang-bot — 2023-11-20T12:23:52Z
dlang/phobos pull request #8845 "Fix Issue 11111 - std.algorithm.canFind should support Needles..." was merged into master:
- a2c2f79dfae38492e2269bcb4e34a6c916c22091 by Nick Treleaven:
Fix Issue 11111 - std.algorithm.canFind should support Needles...
The requirement that each needle must be a range is arbitrary, so remove
it.
Note: This overload of `canFind` calls `find(haystack, needles)` which
calls `startsWith`, which accepts mixed element and range needles.
https://github.com/dlang/phobos/pull/8845