std::default_searcher
Defined in header <functional> | | |
|---|---|---|
template< class ForwardIt, class BinaryPredicate = std::equal_to<> > class default_searcher; | | (since C++17) |
适合与Searcher过载std::search,它将搜索操作委托给预C++17标准库%27 s。std::search...
default_searcher是CopyConstructible和CopyAssignable...
成员函数
STD::默认[医]搜索者::默认[医]搜索者
default_searcher( ForwardIt pat_first, ForwardIt pat_last, BinaryPredicate pred = BinaryPredicate()); | | |
|---|
构造一个default_searcher通过存储pat_first,,,pat_last,和pred...
参数
pat_first, pat_last | - | a pair of iterators designating the string to be searched for |
|---|---|---|
pred | - | a callable object used to determine equality |
例外
的副本构造函数引发的任何异常。BinaryPredicate或ForwardIt...
STD::默认[医]搜索者::操作员%28%29
template< class ForwardIt2 > std::pair<ForwardIt2, ForwardIt2> operator()( ForwardIt2 first, ForwardIt2 last ) const; | | |
|---|
的Searcher重载调用的成员函数。std::search使用此搜索器执行搜索。
返回一对迭代器。i, j,在哪里i是std::search(first, last, pat_first, pat_last, pred)和j是std::next(i,std::distance(pat_first, pat_last))除非std::search退回来last%28不匹配%29,在这种情况下j等号last也一样。
参数
first, last | - | a pair of iterators designating the string to be examined |
|---|
返回值
中的二过去位置的一对迭代器。[首先,最后%29,其中子序列等于。[帕特[医]首先,帕特[医]定义的最后%29pred的副本或一对副本。last否则。
例
二次
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
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::search(in.begin(), in.end(),
std::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二次
另见
search | searches for a range of elements (function template) |
|---|
© cppreference.com在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com

