Namespaces
Variants

std:: boyer_moore_searcher

From cppreference.net
Utilities library
Function objects
Function invocation
(C++17) (C++23)
Identity function object
(C++20)
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++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* )
헤더 파일에 정의됨 <functional>
template < class RandomIt1,

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

class boyer_moore_searcher ;
(C++17부터)

Searcher 오버로드와 함께 사용하기 적합한 검색기로, std::search Boyer-Moore 문자열 검색 알고리즘 을 구현합니다.

std::boyer_moore_searcher CopyConstructible CopyAssignable 요구 사항을 만족합니다.

RandomIt1 LegacyRandomAccessIterator 요구 사항을 충족해야 합니다.

목차

멤버 함수

std::boyer_moore_searcher:: boyer_moore_searcher

boyer_moore_searcher ( RandomIt1 pat_first,

RandomIt1 pat_last,
Hash hf = Hash ( ) ,

BinaryPredicate pred = BinaryPredicate ( ) ) ;

std::boyer_moore_searcher 를 생성하며, pat_first , pat_last , hf , 그리고 pred 의 복사본을 저장하고 필요한 내부 데이터 구조를 설정합니다.

RandomIt1 의 값 타입은 DefaultConstructible , CopyConstructible , 그리고 CopyAssignable 요구 사항을 만족해야 합니다.

타입 std:: iterator_traits < RandomIt1 > :: value_type 의 임의의 두 값 A B 에 대해, pred ( A, B ) == true 이면, hf ( A ) == hf ( B ) true 이어야 합니다.

매개변수

pat_first, pat_last - 검색할 문자열을 지정하는 반복자 쌍
hf - 문자열의 요소를 해시하는 데 사용되는 호출 가능 객체
pred - 동등성을 결정하는 데 사용되는 호출 가능 객체

예외

다음에 의해 발생하는 모든 예외를 던질 수 있습니다:

  • RandomIt1 의 복사 생성자;
  • RandomIt1 의 값 타입의 기본 생성자, 복사 생성자, 복사 할당 연산자; 또는
  • BinaryPredicate 또는 Hash 의 복사 생성자와 함수 호출 연산자.

또한 내부 데이터 구조에 필요한 추가 메모리를 할당할 수 없는 경우 std::bad_alloc 을 던질 수 있습니다.

std::boyer_moore_searcher:: operator()

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

이 멤버 함수는 std::search 의 Searcher 오버로드에 의해 호출되어 이 검색기로 검색을 수행합니다. RandomIt2 LegacyRandomAccessIterator 요구사항을 충족해야 합니다.

RandomIt1 RandomIt2 는 같은 값 타입을 가져야 합니다.

매개변수

first, last - 검사할 문자열을 지정하는 반복자 쌍

반환 값

패턴 [ pat_first , pat_last ) 이 비어있는 경우, std:: make_pair ( first, first ) 을 반환합니다.

그렇지 않으면, [ first , last ) 범위 내에서 pred 에 의해 정의된 대로 [ pat_first , pat_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 haystack =
        "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"};
    if (const auto 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';
    else
        std::cout << "The string " << std::quoted(needle) << " not found\n";
}

출력:

The string "pisci" found at offset 43

참고 항목

요소 범위의 첫 번째 발생을 검색합니다
(함수 템플릿)
표준 C++ 라이브러리 검색 알고리즘 구현
(클래스 템플릿)
Boyer-Moore-Horspool 검색 알고리즘 구현
(클래스 템플릿)