std::experimental::search
來自 cppreference.com
定義於標頭檔案 <experimental/algorithm> |
||
template< class ForwardIterator, class Searcher > ForwardIterator search( ForwardIterator first, ForwardIterator last, |
(庫基礎 TS) | |
在序列 [
first,
last)
中搜索由 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'; else std::cout << "The string " << needle << " not found\n"; }
輸出
The string pisci found at offset 43
[編輯] 參閱
搜尋一個範圍的元素首次出現的位置 (函式模板) |