|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Old binders and adaptors | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Defined in header <functional> | ||
template<class RandomIt1, class Hash=std::hash<typenamestd::iterator_traits<RandomIt1>::value_type>, | (since C++17) | |
A searcher suitable for use with theSearcher overload ofstd::search that implements theBoyer-Moore-Horspool string searching algorithm.
std::boyer_moore_horspool_searcher isCopyConstructible andCopyAssignable.
RandomIt1 must meet the requirements ofLegacyRandomAccessIterator.
Contents |
boyer_moore_horspool_searcher( RandomIt1 pat_first, RandomIt1 pat_last, | ||
Constructs astd::boyer_moore_horspool_searcher by storing copies ofpat_first,pat_last,hf, andpred, setting up any necessary internal data structures.
The value type ofRandomIt1 must beDefaultConstructible,CopyConstructible andCopyAssignable.
For any two valuesA andB of the typestd::iterator_traits<RandomIt1>::value_type, ifpred(A, B)==true, thenhf(A)== hf(B) shall betrue.
| 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 |
Any exceptions thrown by
RandomIt1;RandomIt1; orBinaryPredicate orHash.May also throwstd::bad_alloc if additional memory required for internal data structures cannot be allocated.
template<class RandomIt2> std::pair<RandomIt2, RandomIt2> operator()( RandomIt2 first, RandomIt2 last)const; | ||
The member function called by the Searcher overload ofstd::search to perform a search with this searcher.RandomIt2 must meet the requirements ofLegacyRandomAccessIterator.
RandomIt1 andRandomIt2 must have the same value type.
| first, last | - | a pair of iterators designating the string to be examined |
If the pattern[pat_first, pat_last) is empty, returnsstd::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 bypred is located, orstd::make_pair(last, last) otherwise.
| Feature-test macro | Value | Std | Feature |
|---|---|---|---|
__cpp_lib_boyer_moore_searcher | 201603L | (C++17) | searchers |
#include <algorithm>#include <functional>#include <iomanip>#include <iostream>#include <string_view> int main(){constexprstd::string_view in="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed ""do eiusmod tempor incididunt ut labore et dolore magna aliqua"; conststd::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';elsestd::cout<<"The string "<<std::quoted(needle)<<" not found\n";}
Output:
The string "pisci" found at offset 43
| searches for the first occurrence of a range of elements (function template)[edit] | |
(C++17) | standard C++ library search algorithm implementation (class template)[edit] |
(C++17) | Boyer-Moore search algorithm implementation (class template)[edit] |