Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::boyer_moore_searcher

      From cppreference.com
      <cpp‎ |utility‎ |functional
       
       
      Utilities library
       
      Function objects
      Function invocation
      (C++17)(C++23)
      Identity function object
      (C++20)
      Negators
      (C++17)
      Searchers
      boyer_moore_searcher
      (C++17)
      Old binders and adaptors
      (until C++17*)
      (until C++17*)
      (until C++17*)
      (until C++17*)  
      (until C++17*)
      (until C++17*)(until C++17*)(until C++17*)(until C++17*)
      (until C++20*)
      (until C++20*)
      (until C++17*)(until C++17*)
      (until C++17*)(until C++17*)

      (until C++17*)
      (until C++17*)(until C++17*)(until C++17*)(until C++17*)
      (until C++20*)
      (until C++20*)
       
      Defined in header<functional>
      template<class RandomIt1,

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

      class boyer_moore_searcher;
      (since C++17)

      A searcher suitable for use with theSearcher overload ofstd::search that implements theBoyer-Moore string searching algorithm.

      std::boyer_moore_searcher isCopyConstructible andCopyAssignable.

      RandomIt1 must meet the requirements ofLegacyRandomAccessIterator.

      Contents

      [edit]Member functions

      std::boyer_moore_searcher::boyer_moore_searcher

      boyer_moore_searcher( RandomIt1 pat_first,

                            RandomIt1 pat_last,
                            Hash hf= Hash(),

                            BinaryPredicate pred= BinaryPredicate());

      Constructs astd::boyer_moore_searcher by storing copies ofpat_first,pat_last,hf, andpred, setting up any necessary internal data structures.

      The value type ofRandomIt1 must beDefaultConstructible,CopyConstructible andCopyAssignable.

      For any two valuesA andB of the typestd::iterator_traits<RandomIt1>::value_type, ifpred(A, B)==true, thenhf(A)== hf(B) shall betrue.

      Parameters

      pat_first, pat_last - a pair of iterators designating the string to be searched for
      hf - a callable object used to hash the elements of the string
      pred - a callable object used to determine equality

      Exceptions

      Any exceptions thrown by

      • the copy constructor ofRandomIt1;
      • the default constructor, copy constructor, and copy assignment operator of the value type ofRandomIt1; or
      • the copy constructor and function call operator ofBinaryPredicate orHash.

      May also throwstd::bad_alloc if additional memory required for internal data structures cannot be allocated.

      std::boyer_moore_searcher::operator()

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

      The member function called by the Searcher overload ofstd::search to perform a search with this searcher.RandomIt2 must meet the requirements ofLegacyRandomAccessIterator.

      RandomIt1 andRandomIt2 must have the same value type.

      Parameters

      first, last - a pair of iterators designating the string to be examined

      Return value

      If the pattern[pat_firstpat_last) is empty, returnsstd::make_pair(first, first).

      Otherwise, returns a pair of iterators to the first and one past last positions in[firstlast) where a subsequence that compares equal to[pat_firstpat_last) as defined bypred is located, orstd::make_pair(last, last) otherwise.

      [edit]Notes

      Feature-test macroValueStdFeature
      __cpp_lib_boyer_moore_searcher201603L(C++17)searchers

      [edit]Example

      Run this code
      #include <algorithm>#include <functional>#include <iomanip>#include <iostream>#include <string_view> int main(){constexprstd::string_view haystack="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed ""do eiusmod tempor incididunt ut labore et dolore magna aliqua"; conststd::string_view needle{"pisci"}; if(constauto it=std::search(haystack.begin(), haystack.end(),            std::boyer_moore_searcher(needle.begin(), needle.end()));        it!= haystack.end())std::cout<<"The string "<<std::quoted(needle)<<" found at offset "<< it- haystack.begin()<<'\n';elsestd::cout<<"The string "<<std::quoted(needle)<<" not found\n";}

      Output:

      The string "pisci" found at offset 43

      [edit]See also

      searches for the first occurrence of a range of elements
      (function template)[edit]
      standard C++ library search algorithm implementation
      (class template)[edit]
      Boyer-Moore-Horspool search algorithm implementation
      (class template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/utility/functional/boyer_moore_searcher&oldid=152160"

      [8]ページ先頭

      ©2009-2025 Movatter.jp