std::experimental:: boyer_moore_searcher, std::experimental:: make_boyer_moore_searcher
|
定义于头文件
<experimental/functional>
|
||
|
template
<
class
RandomIt1,
class
Hash
=
std::
hash
<
typename
std::
iterator_traits
<
RandomIt1
>
::
value_type
>
,
|
(库基础技术规范) | |
一种适用于 std::experimental::search 的搜索器,实现了 Boyer-Moore字符串搜索算法 。
boyer_moore_searcher
是
可复制构造
且
可复制赋值
的。
RandomIt1
必须满足
LegacyRandomAccessIterator
的要求。
目录 |
成员函数
std::experimental::boyer_moore_searcher:: boyer_moore_searcher
|
boyer_moore_searcher
(
RandomIt1 pat_first,
RandomIt1 pat_last,
|
||
通过存储
pat_first
、
pat_last
、
hf
和
pred
的副本,构造一个
boyer_moore_searcher
,并设置必要的内部数据结构。
RandomIt1
的值类型必须满足
默认构造
、
拷贝构造
和
拷贝赋值
要求。
对于类型
std::
iterator_traits
<
RandomIt1
>
::
value_type
的任意两个值
A
和
B
,若
pred
(
A, B
)
==
true
,则
hf
(
A
)
==
hf
(
B
)
必须为
true
。
参数
| pat_first, pat_last | - | 指定待搜索字符串的一对迭代器 |
| hf | - | 用于哈希字符串元素的可调用对象 |
| pred | - | 用于判断相等性的可调用对象 |
异常
可能抛出以下异常:
-
RandomIt1的拷贝构造函数抛出的异常; -
RandomIt1值类型的默认构造函数、拷贝构造函数和拷贝赋值运算符抛出的异常;或 -
BinaryPredicate或Hash的拷贝构造函数和函数调用运算符抛出的异常。
如果无法为内部数据结构分配所需内存,可能还会抛出 std::bad_alloc 。
std::experimental::boyer_moore_searcher:: operator()
|
template
<
class
RandomIt2
>
RandomIt2 operator ( ) ( RandomIt2 first, RandomIt2 last ) const ; |
(C++17 前) | |
|
template
<
class
RandomIt2
>
std:: pair < RandomIt2,RandomIt2 > operator ( ) ( RandomIt2 first, RandomIt2 last ) const ; |
(C++17 起) | |
此成员函数由
std::experimental::search
调用,以使用此搜索器执行搜索操作。
RandomIt2
必须满足
LegacyRandomAccessIterator
的要求。
RandomIt1
和
RandomIt2
必须具有相同的值类型。
参数
| first, last | - | 指定待搜索字符串的一对迭代器 |
返回值
|
如果模式
否则,返回指向范围
|
(C++17 前) |
|
如果模式
否则,返回指向范围
|
(C++17 起) |
辅助函数
|
template
<
class
RandomIt,
class
Hash
=
std::
hash
<
typename
std::
iterator_traits
<
RandomIt
>
::
value_type
>
,
|
(库基础技术规范) | |
用于构造
std::experimental::boyer_moore_searcher
的辅助函数,通过模板参数推导实现。等效于
return
boyer_moore_searcher
<
RandomIt, Hash, BinaryPredicate
>
(
pat_first, pat_last, hf, pred
)
;
参数
| pat_first, pat_last | - | 用于指定待搜索字符串的一对迭代器 |
| hf | - | 用于对字符串元素进行哈希处理的可调用对象 |
| pred | - | 用于判断相等性的可调用对象 |
返回值
一个使用参数
pat_first
、
pat_last
、
hf
和
pred
构造的
boyer_moore_searcher
。
示例
#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"; }
输出:
The string pisci found at offset 43
参见
|
搜索元素范围的首次出现
(函数模板) |