首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::boyer_moore_searcher

Defined in header <functional>

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

(since C++17)

一个适合与Searcher过载std::search实现Boyer-Moore字符串搜索算法...

boyer_moore_searcherCopyConstructibleCopyAssignable...

RandomIt1必须符合RandomAccessIterator...

成员函数

STD:Boyer[医]摩尔[医]搜索者::Boyer[医]摩尔[医]搜索者

boyer_moore_searcher( RandomIt1 pat_first, RandomIt1 pat_last, Hash hf = Hash(), BinaryPredicate pred = BinaryPredicate());

构造一个boyer_moore_searcher通过存储pat_first,,,pat_last,,,hf,和pred建立任何必要的内部数据结构。

的值类型RandomIt1一定是DefaultConstructible,,,CopyConstructibleCopyAssignable...

对于任意两个值AB类型std::iterator_traits<RandomIt1>::value_type,如果pred(A, B) == true,然后hf(A) == hf(B)true...

参数

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

例外

引发的任何异常。

  • 的副本构造函数RandomIt1
  • 类型的值类型的默认构造函数、复制构造函数和复制赋值运算符。RandomIt1;或
  • 的复制构造函数和函数调用运算符BinaryPredicateHash...

也可能std::bad_alloc如果无法分配内部数据结构所需的额外内存。

STD:Boyer[医]摩尔[医]搜索者::操作员%28%29

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

(since C++17)

的Searcher重载调用的成员函数。std::search使用此搜索器执行搜索。RandomIt2必须符合RandomAccessIterator...

RandomIt1RandomIt2必须具有相同的值类型。

参数

first, last

-

a pair of iterators designating the string to be examined

返回值

如果模式%28。[帕特[医]首先,帕特[医]最后%29%29为空,返回make_pair(first, first)...

否则,将一对迭代器返回到。[首先,最后%29,其中子序列等于。[帕特[医]首先,帕特[医]定义的最后%29pred位于,或make_pair(last, last)否则。

二次

代码语言:javascript
复制
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
 
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::search(in.begin(), in.end(),
                   std::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";
}

二次

产出:

二次

代码语言:javascript
复制
The string pisci found at offset 43

二次

另见

search

searches for a range of elements (function template)

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券