Namespaces
Variants

std::default_searcher

cppreference.net에서 가져옴
 
 
유틸리티 라이브러리
일반 유틸리티
관계 연산자 (C++20에서 폐기됨)
정수 비교 함수
(C++20)(C++20)(C++20)    
(C++20)
교환 및 타입 연산
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
공통 어휘 타입
(C++11)
(C++17)
(C++17)
(C++17)
(C++11)
(C++17)
(C++23)



 
함수 객체
함수 호출
(C++17)(C++23)
항등 함수 객체
(C++20)
투명 연산자 래퍼
(C++14)
(C++14)
(C++14)
(C++14)  
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)

이전의 바인더 및 어댑터
(C++17까지*)
(C++17까지*)
(C++17까지*)
(C++17까지*)  
(C++17까지*)
(C++17까지*)(C++17까지*)(C++17까지*)(C++17까지*)
(C++20까지*)
(C++20까지*)
(C++17까지*)(C++17까지*)
(C++17까지*)(C++17까지*)

(C++17까지*)
(C++17까지*)(C++17까지*)(C++17까지*)(C++17까지*)
(C++20까지*)
(C++20까지*)
 
헤더 <functional>
template< class ForwardIt, class BinaryPredicate = std::equal_to<> >
class default_searcher;
(C++17부터)에 정의됨

Searcher 오버로드와 함께 사용하기에 적합한 클래스로, std::search 검색 작업을 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

참고 항목

요소 범위의 첫 번째 출현을 검색합니다
(함수 템플릿 & 알고리즘 함수 객체)
보이어-무어 검색 알고리즘 구현
(클래스 템플릿)
보이어-무어-호스풀 검색 알고리즘 구현
(클래스 템플릿)