std::experimental::boyer_moore_searcher, std::experimental::make_boyer_moore_searcher
Defined in header <experimental/functional>
|
||
template
<
class RandomIt1,
class Hash =
std::hash
<
typename
std::iterator_traits
<RandomIt1>
::
value_type
>, |
(library fundamentals TS) | |
A searcher suitable for use with std::experimental::search that implements the Boyer-Moore string searching algorithm
boyer_moore_searcher
is CopyConstructible and CopyAssignable
RandomIt1
must meet the requirements of LegacyRandomAccessIterator
Member functions
std::experimental::boyer_moore_searcher::boyer_moore_searcher
boyer_moore_searcher( RandomIt1 pat_first,
RandomIt1 pat_last, |
||
Constructs a boyer_moore_searcher
by storing copies of pat_first, pat_last, hf, and pred
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
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
BinaryPredicate
orHash
.
May also throw std::bad_alloc if additional memory required for internal data structures cannot be allocated.
std::experimental::boyer_moore_searcher::operator()
template
<
class RandomIt2 >
RandomIt2 operator( ) ( RandomIt2 first, RandomIt2 last ) const ; |
(until C++17) | |
template
<
class RandomIt2 >
std::pair <RandomIt2,RandomIt2> operator( ) ( RandomIt2 first, RandomIt2 last ) const ; |
(since C++17) | |
The member function called by std::experimental::search to perform a search with this searcher. RandomIt2
must meet the requirements of LegacyRandomAccessIterator
RandomIt1
and RandomIt2
must have the same value type.
Parameters
first, last | - | a pair of iterators designating the string to be examined |
Return value
If the pattern
Otherwise, an iterator to the first position in
|
(until C++17) |
If the pattern
Otherwise, returns a pair of iterators to the first and one past last positions in
|
(since C++17) |
Helper Functions
template
<
class RandomIt,
class Hash =
std::hash
<
typename
std::iterator_traits
<RandomIt>
::
value_type
>, |
(library fundamentals TS) | |
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)
;
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
Example
#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
searches for the first occurrence of a range of elements (function template) |