Namespaces
Variants

std::default_searcher

ja.cppreference.net より
 
 
ユーティリティライブラリ
言語サポート
型サポート (基本型、RTTI)
ライブラリ機能テストマクロ (C++20)
プログラムユーティリティ
可変長引数関数
コルーチンサポート (C++20)
契約サポート (C++26)
三方比較
(C++20)
(C++20)(C++20)(C++20)    
(C++20)(C++20)(C++20)

汎用ユーティリティ
関係演算子 (C++20で非推奨)
整数比較関数
(C++20)(C++20)(C++20)    
(C++20)
swap と 型操作
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
共通語彙型
(C++11)
(C++17)
(C++17)
(C++17)
(C++11)
(C++17)
(C++23)



 
関数オブジェクト
関数呼び出し
(C++17)(C++23)
恒等関数オブジェクト
(C++20)
透過的な演算子ラッパー
(C++14)
(C++14)
(C++14)
(C++14)  
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)

旧式のバインダとアダプタ
(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以上)

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,

BinaryPredicate pred = BinaryPredicate ( ) ) ;
(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 >

operator ( ) ( ForwardIt2 first, ForwardIt2 last ) const ;
(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

関連項目

ある範囲の要素の最初の出現位置を検索する
(関数テンプレート & アルゴリズム関数オブジェクト)
Boyer-Moore 検索アルゴリズムの実装
(クラステンプレート)
Boyer-Moore-Horspool 検索アルゴリズムの実装
(クラステンプレート)