名前空間
変種
操作

std::default_searcher

提供: cppreference.com
< cpp‎ | utility‎ | functional
 
 
ユーティリティライブラリ
汎用ユーティリティ
日付と時間
関数オブジェクト
書式化ライブラリ (C++20)
(C++11)
関係演算子 (C++20で非推奨)
整数比較関数
(C++20)
スワップと型操作
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
一般的な語彙の型
(C++11)
(C++17)
(C++17)
(C++17)
(C++17)

初等文字列変換
(C++17)
(C++17)
 
関数オブジェクト
関数ラッパー
(C++11)
(C++11)
関数の部分適用
(C++20)
(C++11)
関数呼び出し
(C++17)
恒等関数オブジェクト
(C++20)
参照ラッパー
(C++11)(C++11)
演算子ラッパー
否定子
(C++17)
検索子
default_searcher
(C++17)
制約付き比較子
古いバインダとアダプタ
(C++17未満)
(C++17未満)
(C++17未満)
(C++17未満)
(C++17未満)(C++17未満)(C++17未満)(C++17未満)
(C++20未満)
(C++20未満)
(C++17未満)(C++17未満)
(C++17未満)(C++17未満)

(C++17未満)
(C++17未満)(C++17未満)(C++17未満)(C++17未満)
(C++20未満)
(C++20未満)
 
ヘッダ <functional> で定義
template< class ForwardIt, class BinaryPredicate = std::equal_to<> >
class default_searcher;
(C++17以上)

検索操作を C++17 より前の標準ライブラリの std::search に移譲する、 std::searchSearcher オーバーロードで使用するのに適したクラス。

default_searcherCopyConstructible かつ CopyAssignable です。

目次

[編集] メンバ関数

std::default_searcher::default_searcher

default_searcher( ForwardIt pat_first,

                  ForwardIt pat_last,

                  BinaryPredicate pred = BinaryPredicate());
(C++17以上)
(C++20未満)
constexpr default_searcher( ForwardIt pat_first,

                            ForwardIt pat_last,

                            BinaryPredicate pred = BinaryPredicate());
(C++20以上)

pat_firstpat_last および pred のコピーを格納することによって default_searcher を構築します。

引数

pat_first, pat_last - 検索する文字列を指定する一組のイテレータ
pred - 等しさを判定するために使用される関数オブジェクト

例外

BinaryPredicate または ForwardIt のコピーコンストラクタによって投げられるあらゆる例外。

std::default_searcher::operator()

template< class ForwardIt2 >

std::pair<ForwardIt2, ForwardIt2>

    operator()( ForwardIt2 first, ForwardIt2 last ) const;
(C++17以上)
(C++20未満)
template< class ForwardIt2 >

constexpr std::pair<ForwardIt2, ForwardIt2>

    operator()( ForwardIt2 first, ForwardIt2 last ) const;
(C++20以上)

この検索子を使用して検索を行うために std::search の Searcher オーバーロードによって呼ばれるメンバ関数。

イテレータ i, j のペアを返します。 ただし istd::search(first, last, pat_first, pat_last, pred)jstd::next(i, std::distance(pat_first, pat_last)) です。 ただし std::searchlast (マッチなし) を返した場合は jlast と等しくなります。

引数

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

[編集] 関連項目

指定範囲の要素に対して検索を行います
(関数テンプレート) [edit]