std::boyer_moore_searcher
| 헤더 <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,
|
||
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++20) |
|
(C++17) |
표준 C++ 라이브러리 검색 알고리즘 구현 (클래스 템플릿) |
| Boyer-Moore-Horspool 검색 알고리즘 구현 (클래스 템플릿) |