ranges::find_end

ranges::find_end (부분 시퀀스 마지막 위치)

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

출처: cppreference

본문

std::ranges::find_end[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> find_end( I1 first1, S1 last1, I2 first2, S2 last2,
                                 Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {} );
}
  • 반환 타입은 subrange<I1>. 일치하는 마지막 부분 시퀀스의 구간을 나타내고, 없으면 빈 구간이에요.
  • ranges::search가 "첫 번째"라면 ranges::find_end는 "마지막"을 찾아요.
std::string s = "ababcab";
std::string pat = "ab";
auto r = std::ranges::find_end(s, pat);
// 마지막 "ab" 구간

부분 시퀀스가 마지막으로 등장하는 위치가 필요할 때 유용해요.

더 알아보기 (Learn more)

cppreference