std::boyer_moore_horspool_searcher

Header: <functional>

A searcher suitable for use with the overload of std::search that implements the Boyer-Moore-Horspool string searching algorithm.

# Declarations

template< class RandomIt1,
class Hash = std::hash<typename std::iterator_traits<RandomIt1>::value_type>,
class BinaryPredicate = std::equal_to<> >
class boyer_moore_horspool_searcher;

(since C++17)

# Parameters

# Return value

If the pattern [pat_first,pat_last) is empty, returns std::make_pair(first, first).

# Notes

Feature-test macro Value Std Feature __cpp_lib_boyer_moore_searcher 201603L (C++17) searchers

# Example

#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <string_view>
 
int main()
{
    constexpr std::string_view in =
        "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed "
        "do eiusmod tempor incididunt ut labore et dolore magna aliqua";
 
    const std::string_view needle{"pisci"};
 
    auto it = std::search(in.begin(), in.end(),
                  std::boyer_moore_horspool_searcher(
                      needle.begin(), needle.end()));
    if (it != in.end())
        std::cout << "The string " << std::quoted(needle) << " found at offset "
                  << it - in.begin() << '\n';
    else
        std::cout << "The string " << std::quoted(needle) << " not found\n";
}

# See also