std::experimental::boyer_moore_horspool_searcher, std::experimental::make_boyer_moore_horspool_searcher
| 定義於標頭檔案 <experimental/functional> |
||
| template< class RandomIt1, class Hash = std::hash<typename std::iterator_traits<RandomIt1>::value_type>, |
(庫基礎 TS) | |
一個適合與 std::experimental::search 一起使用的搜尋器,它實現了 Boyer-Moore-Horspool 字串搜尋演算法。
boyer_moore_horspool_searcher 是 可複製構造的(CopyConstructible) 和 可複製賦值的(CopyAssignable)。
RandomIt1 必須滿足 舊式隨機訪問迭代器(LegacyRandomAccessIterator) 的要求。
目錄 |
[編輯] 成員函式
std::experimental::boyer_moore_horspool_searcher::boyer_moore_horspool_searcher
| boyer_moore_horspool_searcher( RandomIt1 pat_first, RandomIt1 pat_last, |
||
透過儲存 pat_first、pat_last、hf 和 pred 的副本,並設定任何必要的內部資料結構來構造 boyer_moore_horspool_searcher。
RandomIt1 的值型別必須是 可預設構造的(DefaultConstructible)、可複製構造的(CopyConstructible) 和 可複製賦值的(CopyAssignable)。
對於型別為 std::iterator_traits<RandomIt1>::value_type 的任意兩個值 A 和 B,如果 pred(A, B) == true,則 hf(A) == hf(B) 應當為 true。
引數
| pat_first, pat_last | - | 一對迭代器,指示要搜尋的字串 |
| hf | - | 一個可呼叫物件,用於對字串元素進行雜湊 |
| pred | - | 一個可呼叫物件,用於確定相等性 |
異常
由以下任一情況丟擲的任何異常:
RandomIt1的複製建構函式;RandomIt1的值型別的預設建構函式、複製建構函式或複製賦值運算子;或BinaryPredicate或Hash的複製建構函式或函式呼叫運算子。
如果無法為內部資料結構分配所需的額外記憶體,也可能丟擲 std::bad_alloc。
std::experimental::boyer_moore_horspool_searcher::operator()
| template< class RandomIt2 > RandomIt2 operator()( RandomIt2 first, RandomIt2 last ) const; |
(C++17 前) | |
| template< class RandomIt2 > std::pair<RandomIt2,RandomIt2> operator()( RandomIt2 first, RandomIt2 last ) const; |
(C++17 起) | |
由 std::experimental::search 呼叫以使用此搜尋器執行搜尋的成員函式。RandomIt2 必須滿足 舊式隨機訪問迭代器(LegacyRandomAccessIterator) 的要求。
RandomIt1 和 RandomIt2 必須具有相同的值型別。
引數
| first, last | - | 一對迭代器,指示要檢查的字串 |
返回值
|
如果模式 否則,返回 |
(C++17 前) |
|
如果模式 否則,返回一對迭代器,分別指向 |
(C++17 起) |
[編輯] 輔助函式
| template< class RandomIt, class Hash = std::hash<typename std::iterator_traits<RandomIt>::value_type>, |
(庫基礎 TS) | |
使用模板引數推導構造 std::experimental::boyer_moore_horspool_searcher 的輔助函式。等同於 return boyer_moore_horspool_searcher<RandomIt, Hash, BinaryPredicate>(pat_first, pat_last, hf, pred);
[編輯] 引數
| pat_first, pat_last | - | 一對迭代器,指示要搜尋的字串 |
| hf | - | 一個可呼叫物件,用於對字串元素進行雜湊 |
| pred | - | 一個可呼叫物件,用於確定相等性 |
[編輯] 返回值
使用引數 pat_first、pat_last、hf 和 pred 構造的 boyer_moore_horspool_searcher。
[編輯] 示例
#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_horspool_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
[編輯] 參閱
| 搜尋一個範圍的元素首次出現的位置 (函式模板) |