Namespaces
Variants

std::experimental:: search

From cppreference.net
定義於標頭檔 <experimental/algorithm>
template < class ForwardIterator, class Searcher >

ForwardIterator search ( ForwardIterator first, ForwardIterator last,

const Searcher & searcher ) ;
(library fundamentals TS)

シーケンス [ first , last ) 内を、 searcher のコンストラクタで指定されたパターンを検索します。

実質的に searcher ( first, last ) を実行する。

(C++17まで)

実質的に searcher ( first, last ) . first を実行する。

(C++17以降)

Searcher CopyConstructible である必要はありません。

標準ライブラリは以下のサーチャーを提供します:

標準C++ライブラリ検索アルゴリズムの実装
(クラステンプレート)
Boyer-Moore検索アルゴリズムの実装
(クラステンプレート)
Boyer-Moore-Horspool検索アルゴリズムの実装
(クラステンプレート)

目次

パラメータ

戻り値

searcher. operator ( ) の結果を返します。つまり、部分文字列が見つかった位置へのイテレータ、または見つからなかった場合は last のコピーを返します。

計算量

検索方法によります。

#include <experimental/algorithm>
#include <experimental/functional>
#include <iostream>
#include <string>
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::experimental::search(in.begin(), in.end(),
                  std::experimental::make_boyer_moore_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

関連項目

要素の範囲の最初の出現を検索する
(関数テンプレート)