Namespaces
Variants

std::experimental:: search

From cppreference.net
헤더 파일에 정의됨 <experimental/algorithm>
template < class ForwardIterator, class Searcher >

ForwardIterator search ( ForwardIterator first, ForwardIterator last,

const Searcher & searcher ) ;
(라이브러리 펀더멘털 TS)

시퀀스 [ first , last ) 에서 searcher 생성자에 지정된 패턴을 검색합니다.

효과적으로 searcher ( first, last ) 를 실행합니다.

(C++17까지)

효과적으로 searcher ( first, last ) . first 를 실행합니다.

(C++17부터)

Searcher CopyConstructible 일 필요가 없습니다.

표준 라이브러리는 다음과 같은 검색기를 제공합니다:

표준 C++ 라이브러리 검색 알고리즘 구현
(클래스 템플릿)
Boyer-Moore 검색 알고리즘 구현
(클래스 템플릿)
Boyer-Moore-Horspool 검색 알고리즘 구현
(클래스 템플릿)

목차

매개변수

반환값

searcher. operator ( ) 의 결과를 반환합니다. 즉, 부분 문자열이 발견된 위치를 가리키는 반복자 또는 발견되지 않았을 경우 last 의 사본을 반환합니다.

복잡도

검색자에 따라 다릅니다.

예제

#include <experimental/algorithm>
#include <experimental/functional>
#include <iostream>
#include <string>
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::experimental::search(in.begin(), in.end(),
                  std::experimental::make_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";
}

출력:

The string pisci found at offset 43

참고 항목

요소 범위의 첫 번째 발생을 검색합니다
(함수 템플릿)