ranges::search

ranges::search (부분 시퀀스 찾기 — ranges)

범위에서 부분 시퀀스와 일치하는 첫 위치를 찾는 ranges 버전 알고리즘이에요. <algorithm> 헤더에 있어요.

출처: cppreference

본문

std::ranges::search[first1, last1) 안에서 [first2, last2)와 일치하는 첫 부분을 찾아요.

namespace std::ranges {
template< std::forward_iterator I1, std::sentinel_for<I1> S1,
          std::forward_iterator I2, std::sentinel_for<I2> S2,
          class Pred = ranges::equal_to,
          class Proj1 = std::identity, class Proj2 = std::identity >
constexpr subrange<I1> search( I1 first1, S1 last1, I2 first2, S2 last2,
                               Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {} );
}
  • 반환 타입 subrange<I1>로, 첫 일치 구간을 나타내요. 없으면 빈 구간.
std::string s = "abcxabc";
std::string pat = "abc";
auto r = std::ranges::search(s, pat);
// 첫 "abc" 구간

부분 문자열/시퀀스의 첫 등장이 필요할 때 find_end(마지막)와 대비되는 함수예요.

더 알아보기 (Learn more)

cppreference