canFind.canFind

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

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 LREF find returns for the same operation.

  1. bool canFind(Range haystack)
  2. bool canFind(Range haystack, Element needle)
  3. size_t canFind(Range haystack, Ranges needles)
    template canFind(alias pred = "a == b")
    size_t
    canFind
    (
    Range
    Ranges...
    )
    (
    Range haystack
    ,
    scope Ranges needles
    )
    if (
    Ranges.length > 1 &&
    &&
    is(typeof(find!pred(haystack, needles)))
    )

Meta

Suggestion Box / Bug Report