std::default_searcher
| ヘッダ <functional> で定義
|
||
| template< class ForwardIt, class BinaryPredicate = std::equal_to<> > class default_searcher; |
(C++17以上) | |
検索操作を C++17 より前の標準ライブラリの std::search に移譲する、 std::search の Searcher オーバーロードで使用するのに適したクラス。
default_searcher は CopyConstructible かつ CopyAssignable です。
目次 |
[編集] メンバ関数
std::default_searcher::default_searcher
| default_searcher( ForwardIt pat_first, ForwardIt pat_last, |
(C++17以上) (C++20未満) |
|
| constexpr default_searcher( ForwardIt pat_first, ForwardIt pat_last, |
(C++20以上) | |
pat_first、 pat_last および pred のコピーを格納することによって default_searcher を構築します。
引数
| pat_first, pat_last | - | 検索する文字列を指定する一組のイテレータ |
| pred | - | 等しさを判定するために使用される関数オブジェクト |
例外
BinaryPredicate または ForwardIt のコピーコンストラクタによって投げられるあらゆる例外。
std::default_searcher::operator()
| template< class ForwardIt2 > std::pair<ForwardIt2, ForwardIt2> |
(C++17以上) (C++20未満) |
|
| template< class ForwardIt2 > constexpr std::pair<ForwardIt2, ForwardIt2> |
(C++20以上) | |
この検索子を使用して検索を行うために std::search の Searcher オーバーロードによって呼ばれるメンバ関数。
イテレータ 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 | - | 調べる文字列を指定する一組のイテレータ |
戻り値
pred によって定義されるところの [pat_first, pat_last) と比較して等しい部分シーケンスが位置する [first, last) 内の先頭と終端の位置を指すイテレータのペア、またはそうでなければ last のコピーのペア。
[編集] 例
#include <iostream> #include <string> #include <algorithm> #include <functional> 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::search(in.begin(), in.end(), std::default_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
[編集] 関連項目
| 指定範囲の要素に対して検索を行います (関数テンプレート) |