std::experimental::default_searcher, std::experimental::make_default_searcher
| 在标头 <experimental/functional> 定义
|
||
| |
(库基础 TS) | |
适用于 std::experimental::search 的搜索器,将搜索操作委托给标准库的 std::search。
default_searcher 是可复制构造 (CopyConstructible) 且可复制赋值 (CopyAssignable) .
成员函数
std::experimental::default_searcher::default_searcher
| |
||
创建 default_searcher,存储 pat_first、pat_last 和 pred 的副本。
参数
| pat_first, pat_last | - | 代表要搜索字符串的一对迭代器 |
| pred | - | 用于确定相等性的可调用对象 |
异常
由 BinaryPredicate 或 ForwardIterator 的复制构造函数抛出的任何异常。
std::experimental::default_searcher::operator()
| |
(C++17 前) | |
| |
(C++17 起) | |
由 std::experimental::search 调用的成员函数,以此搜索器实施搜索。
|
等价于 |
(C++17 前) |
|
返回一对迭代器 |
(C++17 前) |
参数
| first, last | - | 代表要检查字符串的一对迭代器 |
返回值
|
返回指向 |
(C++17 前) |
|
返回一对迭代器,指向 |
(C++17 起) |
辅助函数
| |
(库基础 TS) | |
利用模板实参推导创建 std::experimental::default_searcher 的辅助函数。等价于 return default_searcher<ForwardIterator, BinaryPredicate>(pat_first, pat_last, pred);
参数
| pat_first, pat_last | - | 代表要搜索字符串的一对迭代器 |
| pred | - | 用于确定相等性的可调用对象 |
返回值
从实参 pat_first、pat_last 和 pred 构造的 default_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_default_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
参阅
| 搜索元素范围的首次出现 (函数模板) |