名稱空間
變體
操作

std::experimental::search

來自 cppreference.com
< cpp‎ | 實驗性
 
 
實驗性
技術規範
檔案系統庫 (檔案系統 TS)
庫基礎 (庫基礎 TS)
庫基礎 2 (庫基礎 TS v2)
庫基礎 3 (庫基礎 TS v3)
並行性擴充套件 (並行性 TS)
並行性擴充套件 2 (並行性 TS v2)
併發性擴充套件 (併發性 TS)
併發擴充套件 2 (concurrency TS v2)
概念 (概念 TS)
範圍 (範圍 TS)
反射 (反射 TS)
數學特殊函式 (特殊函式 TR)
實驗性非 TS
模式匹配
線性代數
std::execution
契約
2D 圖形
 
 
定義於標頭檔案 <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';
    else
        std::cout << "The string " << needle << " not found\n";
}

輸出

The string pisci found at offset 43

[編輯] 參閱

搜尋一個範圍的元素首次出現的位置
(函式模板) [編輯]