std::experi...re_searcher(3)
π std::experimental::boyer_moore_searcher & std::experimental::make_boyer_moore_searcher π
okay bestie, this is the std::experi...re_searcher(3) manual page from the C++ Standard Libary (yes, that's the spelling in the header, we're keeping it π). it's all about std::experimental::boyer_moore_searcher and std::experimental::make_boyer_moore_searcher β a whole duo, and they're here to make Boyer-Moore string searching happen with std::experimental::search. periodt β¨
πΈ NAME πΈ
std::experimental::boyer_moore_searcher, std::experimental::make_boyer_moore_searcher β that's the pair, no cap π
. (The class and the helper function, both in the library fundamentals TS.)
π¦ Synopsis π¦
Defined in header <experimental/functional> β and yes, it's in the library fundamentals TS.
template< class RandomIt1,
class Hash = std::hash<typename std::iterator_traits<RandomIt1>::value_type>,
class BinaryPredicate = std::equal_to<> >
class boyer_moore_searcher;
so boyer_moore_searcher is a searcher suitable for use with std::experimental::search that implements the Boyer-Moore string searching algorithm. it's giving algorithm royalty π.
boyer_moore_searcher is CopyConstructible and CopyAssignable β love that for it π«Ά.
RandomIt1must meet the requirements ofLegacyRandomAccessIterator. no skipping that vibe check, bestie.
π Member functions π
π std::experimental::boyer_moore_searcher::boyer_moore_searcher π
boyer_moore_searcher( RandomIt1 pat_first,
RandomIt1 pat_last,
Hash hf = Hash(),
BinaryPredicate pred = BinaryPredicate() );
Constructs a boyer_moore_searcher by storing copies of pat_first, pat_last, hf, and pred, setting up any necessary internal data structures. it's literally collecting its little ingredients and getting ready to search π§.
The value type of RandomIt1 must be DefaultConstructible, CopyConstructible and CopyAssignable. periodt.
For any two valuesAandBof the typestd::iterator_traits<RandomIt1>::value_type, ifpred(A, B) == true, thenhf(A) == hf(B)shall be true. this is a hard requirement, bestie β don't let your hash and equality be in a situationship where they disagree π.
π Parameters π
pat_first,pat_lastβ a pair of iterators designating the string to be searched for.hfβ a callable object used to hash the elements of the string.predβ a callable object used to determine equality.
π Exceptions π
Any exceptions thrown by:
- the copy constructor of
RandomIt1; - the default constructor, copy constructor, and copy assignment operator of the value type of
RandomIt1; or - the copy constructor and function call operator of
BinaryPredicateorHash.
May also throw std::bad_alloc if additional memory required for internal data structures cannot be allocated. so dramatic, but fair π.
π std::experimental::boyer_moore_searcher::operator() π
until C++17
template< class RandomIt2 >
RandomIt2 operator()( RandomIt2 first, RandomIt2 last ) const;
since C++17
template< class RandomIt2 >
std::pair<RandomIt2,RandomIt2> operator()( RandomIt2 first, RandomIt2 last ) const;
The member function called by std::experimental::search to perform a search with this searcher. RandomIt2 must meet the requirements of LegacyRandomAccessIterator. also, RandomIt1 and RandomIt2 must have the same value type β no mismatched bestie energy π.
π Parameters π
first,lastβ a pair of iterators designating the string to be examined.
π Return value π
until C++17: If the pattern [pat_first, pat_last) is empty, returns first.
Otherwise, an iterator to the first position in [first, last) where a subsequence that compares equal to [pat_first, pat_last) as defined by pred is located, or a copy of last otherwise.
since C++17: If the pattern [pat_first, pat_last) is empty, returns 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 make_pair(last, last) otherwise.
π§ Helper Functions π§
template< class RandomIt,
class Hash = std::hash<typename std::iterator_traits<RandomIt>::value_type>,
class BinaryPredicate = std::equal_to<> >
boyer_moore_searcher<RandomIt, Hash, BinaryPredicate>
make_boyer_moore_searcher(
RandomIt pat_first,
RandomIt pat_last,
Hash hf = Hash(),
BinaryPredicate pred = BinaryPredicate());
Helper function that constructs a std::experimental::boyer_moore_searcher using template argument deduction. Equivalent to return boyer_moore_searcher<RandomIt, Hash, BinaryPredicate>(pat_first, pat_last, hf, pred); β cute, convenient, iconic β¨.
(this one is also in the library fundamentals TS.)
π Parameters π
pat_first,pat_lastβ a pair of iterators designating the string to be searched for.hfβ a callable object used to hash the elements of the string.predβ a callable object used to determine equality.
π Return value π
A boyer_moore_searcher constructed with the arguments pat_first, pat_last, hf, and pred. slay π«Ά.
π Example π
// Run this code
#include <experimental/algorithm>
#include <experimental/functional>
#include <iostream>
#include <string>
int main()
{
std::string in = "Lorem ipsum dolor sit amet, consectetur adipiscing elit,"
" sed do eiusmod tempor incididunt ut labore et dolore magna aliqua";
std::string needle = "pisci";
auto it = std::experimental::search(in.begin(), in.end(),
std::experimental::make_boyer_moore_searcher(
needle.begin(), needle.end()));
if (it != in.end())
std::cout << "The string " << needle << " found at offset "
<< it - in.begin() << '\n';
else
std::cout << "The string " << needle << " not found\n";
}
π Output π
The string pisci found at offset 43
π See also π
searchβ searches for a range of elements (function template).
π·οΈ Category π·οΈ
- Noindexed pages
okay that's the whole page, bestie π source/version/date sign-off vibes: http://cppreference.com, 2024.06.10, and the manual page tag std::experi...re_searcher(3) β that's the footer, and we're done. mwah π
π¦ 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