ranges::is_sorted_until

ranges::is_sorted_until (정렬 깨지는 지점)

범위의 시작부터 정렬된 가장 긴 접두 구간의 끝을 찾는 ranges 버전 알고리즘이에요. <algorithm> 헤더에 있어요.

출처: cppreference

본문

std::ranges::is_sorted_until은 정렬 순서를 유지하는 가장 긴 접두 구간 [first, it)의 끝 it를 반환해요.

namespace std::ranges {
template< class R, class Proj = std::identity,
          std::indirect_strict_weak_order<std::projected<ranges::iterator_t<R>, Proj>>
              Comp = ranges::less >
constexpr ranges::borrowed_iterator_t<R>
    is_sorted_until( R&& r, Comp comp = {}, Proj proj = {} );
}
std::vector<int> v{1, 2, 3, 5, 4, 6};
auto it = std::ranges::is_sorted_until(v);
// 4를 가리킴 (1,2,3,5까지 정렬)

"어디까지 정렬돼 있는지"를 알려주는 ranges 버전이에요.

더 알아보기 (Learn more)

cppreference