std::experimental::search

来自cppreference.com
在标头 <experimental/algorithm> 定义
template<class ForwardIterator, class Searcher >

ForwardIterator search( ForwardIterator first, ForwardIterator last,

                        const Searcher& searcher );
(库基础 TS)

在序列 [firstlast) 中搜索 searcher 的构造函数所指定的模式。

相当于执行 searcher(first, last)

(C++17 前)

相当于执行 searcher(first, last).first

(C++17 起)

Searcher 不必为可复制构造(CopyConstructible)

标准库提供了下列搜索器:

标准 C++ 库搜索算法实现
(类模板)
Boyer-Moore 搜索算法实现
(类模板)
Boyer-Moore-Horspool 搜索算法实现
(类模板)

目录

[编辑]参数

[编辑]返回值

返回 searcher.operator() 的结果,即指向找到子字符串的位置的迭代器,或当未找到时返回 last 的副本。

[编辑]复杂度

取决于搜索器。

[编辑]示例

#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';elsestd::cout<<"The string "<< needle <<" not found\n";}

输出:

The string pisci found at offset 43

[编辑]参阅

搜索元素范围的首次出现
(函数模板)[编辑]
close