View source code
Display the source code in std/algorithm/searching.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

std.algorithm.searching.canFind.canFind - multiple declarations

Function canFind.canFind

Returns true if and only if pred(e) is true for any value e in the input range range. Performs (at most) Ο(haystack.length) evaluations of pred.

bool canFind(Range) (
  Range haystack
)
if (is(typeof(find!pred(haystack))));

Function canFind.canFind

Returns true if and only if needle can be found in range. Performs Ο(haystack.length) evaluations of pred.

bool canFind(Range, Element) (
  Range haystack,
  scope Element needle
)
if (is(typeof(find!pred(haystack, needle))));

Function canFind.canFind

Returns the 1-based index of the first needle found in haystack. If no needle is found, then 0 is returned.

size_t canFind(Range, Needles...) (
  Range haystack,
  scope Needles needles
)
if (Needles.length > 1 && is(typeof(find!pred(haystack, needles))));

So, 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, whereas if the result is used elsewhere, it can either be cast to bool for the same effect or used to get which needle was found first without having to deal with the tuple that find returns for the same operation.

Authors

Andrei Alexandrescu

License

Boost License 1.0.