std::boyer_moore_searcher
| ヘッダ <functional> で定義 |
||
| template< class RandomIt1, class Hash = std::hash<typename std::iterator_traits<RandomIt1>::value_type>, |
(C++17以降) | |
Searcher の std::search オーバーロードで使用するのに適したセッチャーで、Boyer-Moore文字列検索アルゴリズムを実装しています。
std::boyer_moore_searcher は、CopyConstructible および CopyAssignable です。
RandomIt1はLegacyRandomAccessIteratorの要件を満たす必要があります。
目次 |
[edit] メンバ関数
std::boyer_moore_searcher::boyer_moore_searcher
| boyer_moore_searcher( RandomIt1 pat_first, RandomIt1 pat_last, |
||
pat_first, pat_last, hf, および pred のコピーを格納し、必要な内部データ構造をセットアップして、std::boyer_moore_searcher を構築します。
RandomIt1のvalue typeは、DefaultConstructible、CopyConstructible、およびCopyAssignableである必要があります。
型 std::iterator_traits<RandomIt1>::value_type の任意の2つの値 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::boyer_moore_searcher::operator()
| template< class RandomIt2 > std::pair<RandomIt2, RandomIt2> operator()( RandomIt2 first, RandomIt2 last ) const; |
(C++17以降) | |
このセッチャーを使用して検索を実行するために、std::search の Searcher オーバーロードによって呼び出されるメンバ関数です。RandomIt2 は LegacyRandomAccessIterator の要件を満たす必要があります。
RandomIt1とRandomIt2は同じvalue typeを持つ必要があります。
パラメータ
| first, last | - | 検査対象の文字列を指定するイテレータのペア |
戻り値
パターン [pat_first, pat_last) が空の場合、std::make_pair(first, first) を返します。
それ以外の場合、pred によって定義されるように、[pat_first, pat_last) と比較して等しい部分シーケンスが配置される、[first, last) 内の最初の位置と最後の次の位置へのイテレータのペア、またはそれ以外の場合は std::make_pair(last, last) を返します。
[edit] 注記
| 機能テストマクロ | 値 | 規格 | 機能 |
|---|---|---|---|
__cpp_lib_boyer_moore_searcher |
201603L |
(C++17) | 検索子 |
[edit] 例
#include <algorithm> #include <functional> #include <iomanip> #include <iostream> #include <string_view> int main() { constexpr std::string_view haystack = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed " "do eiusmod tempor incididunt ut labore et dolore magna aliqua"; const std::string_view needle{"pisci"}; if (const auto it = std::search(haystack.begin(), haystack.end(), std::boyer_moore_searcher(needle.begin(), needle.end())); it != haystack.end() ) std::cout << "The string " << std::quoted(needle) << " found at offset " << it - haystack.begin() << '\n'; else std::cout << "The string " << std::quoted(needle) << " not found\n"; }
出力
The string "pisci" found at offset 43
[edit] 関連項目
| 要素の範囲の最初の出現を検索する (関数テンプレート) | |
| (C++17) |
標準C++ライブラリの探索アルゴリズム実装 (クラステンプレート) |
| ボイヤー・ムーア・ホースプール法探索アルゴリズム実装 (クラステンプレート) |