名前空間
変種
操作

std::boyer_moore_horspool_searcher

From cppreference.com
< cpp‎ | utility‎ | functional
 
 
ユーティリティライブラリ
言語サポート
型のサポート (基本型、RTTI)
ライブラリ機能検査マクロ (C++20)
プログラムユーティリティ
可変引数関数
コルーチンサポート (C++20)
契約サポート (C++26)
三方比較
(C++20)
(C++20)(C++20)(C++20)  
(C++20)(C++20)(C++20)

汎用ユーティリティ
関係演算子 (C++20で非推奨)
 
関数オブジェクト
関数の呼び出し
(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)

否定子 (Negators)
(C++17)
サーチャー
boyer_moore_horspool_searcher
(C++17)    
古いバインダとアダプタ
(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 RandomIt1,

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

class boyer_moore_horspool_searcher;
(C++17以降)

std::searchstd::searchオーバーロードで使用するための検索器で、Boyer-Moore-Horspool文字列検索アルゴリズムを実装します。Searcher overload of std::search that implements the Boyer-Moore-Horspool string searching algorithm.

std::boyer_moore_horspool_searcherCopyConstructibleであり、CopyAssignableです。

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

目次

[編集] メンバ関数

std::boyer_moore_horspool_searcher::boyer_moore_horspool_searcher

boyer_moore_horspool_searcher( RandomIt1 pat_first,

                               RandomIt1 pat_last,
                               Hash hf = Hash(),

                               BinaryPredicate pred = BinaryPredicate() );

pat_firstpat_lasthf、およびpredのコピーを格納し、必要な内部データ構造をセットアップして、std::boyer_moore_horspool_searcherを構築します。

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

value type 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のvalue typeのデフォルトコンストラクタ、コピーコンストラクタ、またはコピー代入演算子。
  • BinaryPredicateまたはHashのコピーコンストラクタまたは関数呼び出し演算子。

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

std::boyer_moore_horspool_searcher::operator()

template< class RandomIt2 >
std::pair<RandomIt2, RandomIt2> operator()( RandomIt2 first, RandomIt2 last ) const;

この検索器を使用して検索を実行するために、std::searchのSearcherオーバーロードによって呼び出されるメンバ関数です。RandomIt2LegacyRandomAccessIteratorの要件を満たす必要があります。

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

パラメータ

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

戻り値

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

それ以外の場合、[firstlast) の中で、predによって定義されるように [pat_firstpat_last) と等価な部分列が見つかった最初の位置と最後の次の位置を示すイテレータのペア、またはそうでない場合は std::make_pair(last, last) を返します。

[編集] 注記

機能テストマクロ 規格 機能
__cpp_lib_boyer_moore_searcher 201603L (C++17) 検索子

[編集]

#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::boyer_moore_horspool_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

[編集] 関連項目

要素の範囲の最初の出現を検索する
(関数テンプレート) [編集]
標準C++ライブラリの探索アルゴリズム実装
(クラステンプレート) [編集]
ボイヤー・ムーア法探索アルゴリズム実装
(クラステンプレート) [編集]
English 日本語 中文(简体) 中文(繁體)