Namespaces
Variants

std:: default_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 ForwardIt, class BinaryPredicate = std:: equal_to <> >
class default_searcher ;
(C++17부터)

Searcher 오버로드와 함께 사용하기 적합한 클래스로, 검색 작업을 C++17 이전 표준 라이브러리의 std::search 에 위임합니다.

std::default_searcher CopyConstructible CopyAssignable 입니다.

목차

멤버 함수

std::default_searcher:: default_searcher

default_searcher ( ForwardIt pat_first,

ForwardIt pat_last,

BinaryPredicate pred = BinaryPredicate ( ) ) ;
(C++17부터)
(C++20부터 constexpr)

std::default_searcher 를 생성하며, pat_first , pat_last , 그리고 pred 의 복사본을 저장합니다.

매개변수

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

예외

BinaryPredicate 또는 ForwardIt 의 복사 생성자에 의해 발생하는 모든 예외.

std::default_searcher:: operator()

template < class ForwardIt2 >

std:: pair < ForwardIt2, ForwardIt2 >

operator ( ) ( ForwardIt2 first, ForwardIt2 last ) const ;
(C++17부터)
(C++20부터 constexpr)

이 멤버 함수는 std::search 의 Searcher 오버로드에 의해 호출되어 이 검색기로 검색을 수행합니다.

반복자 쌍 i, j 를 반환합니다. 여기서 i std:: search ( first, last, pat_first, pat_last, pred ) 이고 j std:: next ( i, std:: distance ( pat_first, pat_last ) ) 입니다. 단, std::search last 를 반환한 경우(일치 항목 없음)에는 j last 와 같습니다.

매개변수

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

반환 값

[ first , last ) 범위 내에서 [ pat_first , pat_last ) pred 에 의해 정의된 대로 동일한 부분 시퀀스가 위치한 첫 번째 위치와 마지막 위치 다음을 가리키는 반복자 쌍, 또는 그렇지 않으면 last 의 복사본 쌍.

예제

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

참고 항목

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