std::experimental::boyer_moore_searcher, std::experimental::make_boyer_moore_searcher
template< class RandomIt1,
class Hash = std::hash<typename std::iterator_traits<RandomIt1>::value_type>,
class BinaryPredicate = std::equal_to<> >
class boyer_moore_searcher;
|
(library fundamentals TS) | |
と共に使用するのに適したサーチャーでstd::experimental::searchを実装するBoyer-Moore string searching algorithm。
boyer_moore_searcherはCopyConstructibleかつCopyAssignableである。
RandomIt1はLegacyRandomAccessIteratorの要件を満たさなければならない。
メンバー関数
std::experimental::boyer_moore_searcher::boyer_moore_searcher
boyer_moore_searcher( RandomIt1 pat_first,
RandomIt1 pat_last,
Hash hf = Hash(),
BinaryPredicate pred = BinaryPredicate() );
|
||
構築するboyer_moore_searcherのコピーを保存し、pat_first、pat_last、hf、およびpred、必要な内部データ構造を設定する。
の値型はRandomIt1でなければならないDefaultConstructible、CopyConstructibleとCopyAssignable。
任意の2つの値AとBの型std::iterator_traits<RandomIt1>::value_typeに対して、もし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_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>,
class BinaryPredicate = std::equal_to<> >
boyer_moore_searcher<RandomIt, Hash, BinaryPredicate> make_boyer_moore_searcher(
RandomIt pat_first,
RandomIt pat_last,
Hash hf = Hash(),
BinaryPredicate pred = BinaryPredicate());
|
(ライブラリ基礎 TS) | |
テンプレート実引数推定を使用してstd::experimental::boyer_moore_searcherを構築するヘルパー関数。return boyer_moore_searcher<RandomIt, Hash, BinaryPredicate>(pat_first, pat_last, hf, pred);
パラメータ
| pat_first, pat_last | - | 検索対象の文字列を指定するイテレータのペア |
| hf | - | 文字列の要素をハッシュするために使用される呼び出し可能オブジェクト |
| pred | - | 等価性を判定するために使用される呼び出し可能オブジェクト |
戻り値
boyer_moore_searcher
は、引数
pat_first
、
pat_last
、
hf
、および
pred
で構築されます。
例
#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
関連項目
| 要素の範囲内の最初の出現を検索する (関数テンプレート & アルゴリズム関数オブジェクト) | |
(C++20) |