名前空間
変種
操作

std::experimental::boyer_moore_searcher, std::experimental::make_boyer_moore_searcher

From cppreference.com
 
 
 
 
ヘッダ <experimental/functional> で定義
template< class RandomIt1,

          class Hash = std::hash<typename std::iterator_traits<RandomIt1>::value_type>,
          class BinaryPredicate = std::equal_to<> >

class boyer_moore_searcher;
(Library Fundamentals TS)

std::experimental::search で使用するために適したセチャーで、Boyer-Moore文字列検索アルゴリズムを実装しています。

boyer_moore_searcherCopyConstructible および CopyAssignable です。

RandomIt1LegacyRandomAccessIteratorの要件を満たす必要があります。

目次

[edit] メンバ関数

std::experimental::boyer_moore_searcher::boyer_moore_searcher

boyer_moore_searcher( RandomIt1 pat_first,

                      RandomIt1 pat_last,
                      Hash hf = Hash(),

                      BinaryPredicate pred = BinaryPredicate() );

pat_first, pat_last, hf, および pred のコピーを格納し、必要な内部データ構造を設定して boyer_moore_searcher を構築します。

RandomIt1のvalue typeは、DefaultConstructibleCopyConstructible、およびCopyAssignableである必要があります。

std::iterator_traits<RandomIt1>::value_type の任意の2つの値 AB について、pred(A, B) == true ならば、hf(A) == hf(B)true である必要があります。

パラメータ

pat_first, pat_last - 検索対象の文字列を指定するイテレータのペア
hf - 文字列の要素をハッシュするために使用される呼び出し可能なオブジェクト
pred - 等価性を判断するために使用される呼び出し可能なオブジェクト

例外

によってスローされる例外

  • RandomIt1のコピーコンストラクタ。
  • RandomIt1 の値型のデフォルトコンストラクタ、コピーコンストラクタ、およびコピー代入演算子。または、
  • BinaryPredicate または Hash のコピーコンストラクタおよび関数呼び出し演算子。

内部データ構造に必要な追加メモリを割り当てられない場合、std::bad_allocをスローする可能性があります。

std::experimental::boyer_moore_searcher::operator()

template< class RandomIt2 >
RandomIt2 operator()( RandomIt2 first, RandomIt2 last ) const;
(C++17まで)
template< class RandomIt2 >
std::pair<RandomIt2,RandomIt2> operator()( RandomIt2 first, RandomIt2 last ) const;
(C++17以降)

std::experimental::search によってこのセチャーで検索を実行するために呼び出されるメンバ関数。RandomIt2LegacyRandomAccessIterator の要件を満たす必要があります。

RandomIt1RandomIt2は同じvalue typeを持つ必要があります。

パラメータ

first, last - 検査対象の文字列を指定するイテレータのペア

戻り値

パターン [pat_firstpat_last) が空の場合、first を返します。

それ以外の場合、[firstlast) 内で、pred によって定義されるように [pat_firstpat_last) と比較して等しい部分シーケンスが見つかる最初の位置へのイテレータ、またはそれ以外の場合は last のコピーを返します。

(C++17まで)

パターン [pat_firstpat_last) が空の場合、make_pair(first, first) を返します。

それ以外の場合、[firstlast) 内で、pred によって定義されるように [pat_firstpat_last) と比較して等しい部分シーケンスが見つかる最初の位置と最後の次の位置へのイテレータのペア、またはそれ以外の場合は make_pair(last, last) を返します。

(C++17以降)

[edit] ヘルパー関数

template< class RandomIt,

          class Hash = std::hash<typename std::iterator_traits<RandomIt>::value_type>,
          class BinaryPredicate = std::equal_to<> >
boyer_moore_searcher<RandomIt, Hash, BinaryPredicate> make_boyer_moore_searcher(
    RandomIt pat_first,
    RandomIt pat_last,
    Hash hf = Hash(),

    BinaryPredicate pred = BinaryPredicate());
(Library Fundamentals TS)

テンプレート引数推論を使用して std::experimental::boyer_moore_searcher を構築するヘルパー関数。 return boyer_moore_searcher<RandomIt, Hash, BinaryPredicate>(pat_first, pat_last, hf, pred); と同等です。

[edit] パラメータ

pat_first, pat_last - 検索対象の文字列を指定するイテレータのペア
hf - 文字列の要素をハッシュするために使用される呼び出し可能なオブジェクト
pred - 等価性を判断するために使用される呼び出し可能なオブジェクト

[edit] 戻り値

引数 pat_first, pat_last, hf, および pred を使用して構築された boyer_moore_searcher

[edit]

#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

[edit] 関連項目

要素の範囲の最初の出現を検索する
(関数テンプレート) [編集]
English 日本語 中文(简体) 中文(繁體)