std::boyer_moore_searcher
Min standard notice:
Header: <functional>
A searcher suitable for use with the overload of std::search that implements the Boyer-Moore 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_searcher;
(since C++17)
# Parameters
pat_first, pat_last: a pair of iterators designating the string to be searched forhf: a callable object used to hash the elements of the stringpred: a callable object used to determine equality
# 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 haystack =
"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"};
if (const auto it = std::search(haystack.begin(), haystack.end(),
std::boyer_moore_searcher(needle.begin(), needle.end()));
it != haystack.end()
)
std::cout << "The string " << std::quoted(needle) << " found at offset "
<< it - haystack.begin() << '\n';
else
std::cout << "The string " << std::quoted(needle) << " not found\n";
}