folly::qfind

qfind overloads

Synopses

Declared in <folly/Range.h>

Finds the first occurrence of needle in haystack. The result is the offset reported to the beginning of haystack, or string::npos if needle wasn't found.

template<class Iter>
size_t
qfind(
    Range<Iter> const& haystack,
    Range<Iter>::value_type const& needle);
» more...
template<>
size_t
qfind<char const*>(
    Range<char const*> const& haystack,
    char const& needle);
» more...
template<>
size_t
qfind<unsigned char const*>(
    Range<unsigned char const*> const& haystack,
    unsigned char const& needle);
» more...

Finds the first occurrence of needle in haystack. The algorithm is on average faster than O(haystack.size() * needle.size()) but not as fast as Boyer-Moore. On the upside, it does not do any upfront preprocessing and does not allocate memory.

template<
    class Iter,
    class Comp = std::equal_to<Range<Iter>::value_type>>
size_t
qfind(
    Range<Iter> const& haystack,
    Range<Iter> const& needle,
    Comp eq = Comp());
» more...

Return Value

The offset of the first match, or npos if not found.

Parameters

NameDescription
haystackThe range to search within.
needleThe element to search for.
eqThe equality comparison used to match elements.