std:: default_searcher
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Old binders and adaptors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
定義済みヘッダー
<functional>
|
||
|
template
<
class
ForwardIt,
class
BinaryPredicate
=
std::
equal_to
<>
>
class default_searcher ; |
(C++17以降) | |
Searcher 要件と共に使用するのに適したクラスであり、 std::search のオーバーロードで、検索操作をC++17以前の標準ライブラリの std::search に委譲します。
std::default_searcher
は
CopyConstructible
かつ
CopyAssignable
です。
目次 |
メンバー関数
std::default_searcher:: default_searcher
|
default_searcher
(
ForwardIt pat_first,
ForwardIt pat_last,
|
(C++17以降)
(C++20以降constexpr) |
|
std::default_searcher
を構築し、
pat_first
、
pat_last
、および
pred
のコピーを格納します。
パラメータ
| pat_first, pat_last | - | 検索対象の文字列を指定するイテレータのペア |
| pred | - | 等価性を判定するために使用される呼び出し可能オブジェクト |
例外
BinaryPredicate
または
ForwardIt
のコピーコンストラクタによってスローされるあらゆる例外。
std::default_searcher:: operator()
|
template
<
class
ForwardIt2
>
std::
pair
<
ForwardIt2, ForwardIt2
>
|
(C++17以降)
(C++20以降 constexpr) |
|
Searcherオーバーロードの std::search によって呼び出され、このサーチャーで検索を実行するメンバー関数。
イテレータのペア
i, j
を返す。ここで
i
は
std::
search
(
first, last, pat_first, pat_last, pred
)
であり、
j
は
std::
next
(
i,
std::
distance
(
pat_first, pat_last
)
)
である。ただし
std::search
が
last
を返した場合(マッチなし)は、
j
も
last
と等しくなる。
パラメータ
| first, last | - | 検索対象の文字列を指定するイテレータのペア |
戻り値
[
first
,
last
)
の範囲内で、
[
pat_first
,
pat_last
)
と
pred
によって定義される等値比較で等しい部分シーケンスが位置する最初と最後の次を指すイテレータのペア。見つからない場合は
last
のコピーのペア。
例
#include <algorithm> #include <functional> #include <iomanip> #include <iostream> #include <string_view> int main() { constexpr std::string_view in = "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"}; auto it = std::search(in.begin(), in.end(), std::default_searcher( needle.begin(), needle.end())); if (it != in.end()) std::cout << "The string " << std::quoted(needle) << " found at offset " << it - in.begin() << '\n'; else std::cout << "The string " << std::quoted(needle) << " not found\n"; }
出力:
The string "pisci" found at offset 43
関連項目
|
要素の範囲の最初の出現を検索する
(関数テンプレート) |
|
|
(C++17)
|
Boyer-Moore検索アルゴリズムの実装
(クラステンプレート) |
|
(C++17)
|
Boyer-Moore-Horspool検索アルゴリズムの実装
(クラステンプレート) |