std::boyer_...ol_searcher(3)
π
std::boyer_...ol_searcher(3) β C++ Standard Libary realness
Okay bestie, this is the manual page for std::boyer_...ol_searcher(3) from the C++ Standard Libary, and we are about to make search algorithms make sense. No cap. π«Ά
πΈ NAME πΈ
std::boyer_moore_horspool_searcher β and yeah, thatβs also the NAME line, because this page said it twice and we respect the duplication era. π
β¨ Synopsis β¨
Defined in header <functional>.
template< class RandomIt1,
class Hash = std::hash<typename std::iterator_traits<RandomIt1>::value_type>,
class BinaryPredicate = std::equal_to<> >
class boyer_moore_horspool_searcher;
This class has been around (since C++17), icon behavior only. β
Itβs a searcher suitable for use with the Searcher overload of std::search that implements the Boyer-Moore-Horspool string searching algorithm. Thatβs the whole vibe: a searcher made for that specific std::search overload, implementing Boyer-Moore-Horspool.
std::boyer_moore_horspool_searcher is CopyConstructible and CopyAssignable. Copy girlies, rise. π
RandomIt1 must meet the requirements of LegacyRandomAccessIterator. Periodt.
π§ Member functions π§
π οΈ std::boyer_moore_horspool_searcher::boyer_moore_horspool_searcher
boyer_moore_horspool_searcher( RandomIt1 pat_first,
RandomIt1 pat_last,
Hash hf = Hash(),
BinaryPredicate pred = BinaryPredicate() );
This constructor constructs a std::boyer_moore_horspool_searcher by storing copies of pat_first, pat_last, hf, and pred, setting up any necessary internal data structures. Very βI made copies and Iβm organized about itβ of it. π
The value type of RandomIt1 must be DefaultConstructible, CopyConstructible and CopyAssignable.
For any two values A and B of the type std::iterator_traits<RandomIt1>::value_type, if pred(A, B) == true, then hf(A) == hf(B) shall be true. Thatβs the rule, bestie. π¦
πΈ 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
π Exceptions π
Any exceptions thrown by:
- the copy constructor of
RandomIt1; - the default constructor, copy constructor, or copy assignment operator of the value type of
RandomIt1; or - the copy constructor or function call operator of
BinaryPredicateorHash.
May also throw std::bad_alloc if additional memory required for internal data structures cannot be allocated. So yeah, memory said βnot todayβ possibly. π
π std::boyer_moore_horspool_searcher::operator()
template< class RandomIt2 >
std::pair<RandomIt2, RandomIt2> operator()( RandomIt2 first, RandomIt2 last ) const;
This is the member function called by the Searcher overload of std::search to perform a search with this searcher. RandomIt2 must meet the requirements of LegacyRandomAccessIterator.
RandomIt1 and RandomIt2 must have the same value type. Matching value types only, iykyk. π
πΈ Parameters πΈ
first,lastβ a pair of iterators designating the string to be examined
π Return value π
If the pattern [pat_first, pat_last) is empty, returns std::make_pair(first, first).
Otherwise, returns a pair of iterators to the first and one past last positions in [first, last) where a subsequence that compares equal to [pat_first, pat_last) as defined by pred is located, or std::make_pair(last, last) otherwise. Found bestie or not-found bestie, no in-between. β¨
π Notes π
Feature-test macro realness:
__cpp_lib_boyer_moore_searcherβ201603Lβ(C++17)βsearchers
π Example π
// Run this code
#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";
}
π Output π
The string "pisci" found at offset 43
π¦ See also π¦
searchβ searches for a range of elements (function template)default_searcherβ standard C++ library search algorithm implementation(C++17)(class template)boyer_moore_searcherβ Boyer-Moore search algorithm implementation(C++17)(class template)
xoxo, your Unix bestie π«Ά source/version/date: http://cppreference.com, 2024.06.10, std::boyer_...ol_searcher(3). Slay. π
β¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms