ranges::partition_point

ranges::partition_point (분할 경계 — ranges)

분할된 범위에서 술어가 거짓이 되는 첫 지점을 찾는 ranges 버전 알고리즘이에요. <algorithm> 헤더에 있어요.

출처: cppreference

본문

std::ranges::partition_point는 분할된 범위에서 술어 pred가 처음 거짓이 되는 위치를 반환해요.

namespace std::ranges {
template< std::forward_iterator I, std::sentinel_for<I> S,
          class Proj = std::identity,
          std::indirect_unary_predicate<std::projected<I, Proj>> Pred >
constexpr I partition_point( I first, S last, Pred pred, Proj proj = {} );
}
  • 범위는 pred 기준으로 분할되어 있어야 해요.
  • 복잡도: O(log N)pred 호출.
std::vector<int> v{2, 4, 6, 1, 3, 5};   // 짝수 먼저 분할
auto it = std::ranges::partition_point(v, [](int x){ return x % 2 == 0; });
// 첫 홀수(1)

분할된 범위에서 경계를 로그 시간에 찾는 ranges 버전이에요.

더 알아보기 (Learn more)

cppreference