首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

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_searcherCopyConstructibleCopyAssignable...

成员函数

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

例外

的副本构造函数引发的任何异常。BinaryPredicateForwardIt...

STD::默认[医]搜索者::操作员%28%29

template< class ForwardIt2 > std::pair<ForwardIt2, ForwardIt2> operator()( ForwardIt2 first, ForwardIt2 last ) const;

的Searcher重载调用的成员函数。std::search使用此搜索器执行搜索。

返回一对迭代器。i, j,在哪里istd::search(first, last, pat_first, pat_last, pred)jstd::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否则。

二次

代码语言:javascript
复制
#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";
}

二次

产出:

二次

代码语言:javascript
复制
The string pisci found at offset 43

二次

另见

search

searches for a range of elements (function template)

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券