std:: boyer_moore_searcher
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Old binders and adaptors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
定義先ヘッダ
<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
の要件を満たさなければならない。
目次 |
メンバー関数
std::boyer_moore_searcher:: boyer_moore_searcher
|
boyer_moore_searcher
(
RandomIt1 pat_first,
RandomIt1 pat_last,
|
||
std::boyer_moore_searcher
を構築し、
pat_first
、
pat_last
、
hf
、および
pred
のコピーを格納し、必要な内部データ構造を設定します。
RandomIt1
の値型は、
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
は同じ値型を持たなければならない。
パラメータ
| first, last | - | 検索対象の文字列を指定するイテレータのペア |
戻り値
パターン
[
pat_first
,
pat_last
)
が空の場合、
std::
make_pair
(
first, first
)
を返す。
それ以外の場合、
[
first
,
last
)
内で、
pred
によって定義される方法で
[
pat_first
,
pat_last
)
と等しいと比較される部分列が位置する最初と最後の次を指すイテレータのペアを返す。見つからない場合は
std::
make_pair
(
last, last
)
を返す。
注記
| 機能テスト マクロ | 値 | 標準 | 機能 |
|---|---|---|---|
__cpp_lib_boyer_moore_searcher
|
201603L
|
(C++17) | サーチャー |
例
#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
関連項目
|
要素の範囲の最初の出現を検索する
(関数テンプレート) |
|
|
(C++17)
|
標準C++ライブラリの検索アルゴリズム実装
(クラステンプレート) |
|
(C++17)
|
Boyer-Moore-Horspool検索アルゴリズムの実装
(クラステンプレート) |