ranges::lower_bound
ranges::lower_bound (하한 경계 — ranges)
정렬된 범위에서 주어진 값보다 작지 않은 첫 원소를 찾는 ranges 버전 알고리즘이에요. <algorithm> 헤더에 있어요.
출처: cppreference
본문
std::ranges::lower_bound는 정렬된 범위에서 value보다 작지 않은 첫 원소를 찾아요.
namespace std::ranges {
template< std::forward_iterator I, std::sentinel_for<I> S, class T,
class Proj = std::identity,
std::indirect_strict_weak_order<const T*, std::projected<I, Proj>>
Comp = ranges::less >
constexpr I lower_bound( I first, S last, const T& value,
Comp comp = {}, Proj proj = {} );
}
- 반환 값:
value보다 크거나 같은 첫 원소 반복자. 없으면last. - 복잡도: 로그적.
std::vector<int> v{1, 2, 2, 4, 5};
auto it = std::ranges::lower_bound(v, 2);
// 첫 2를 가리킴
정렬 유지 삽입 위치나 값 구간 계산에 쓰는 ranges 버전이에요.