flat_map::lower_bound
flat_map::lower_bound (하한 경계)
flat_map에서 특정 키보다 작지 않은 첫 요소를 찾는 멤버 함수예요. <flat_map> 헤더, C++23부터.
출처: cppreference
본문
lower_bound는 key보다 작지 않은(즉 key <= 인) 첫 요소를 찾아요.
iterator lower_bound( const Key& key );
const_iterator lower_bound( const Key& key ) const;
template< class K > iterator lower_bound( const K& x );
- 반환 값:
key보다 크거나 같은 첫 요소 반복자. 없으면end(). - flat_map은 정렬 벡터라 로그 시간(이진 탐색)으로 동작해요.
std::flat_map<int, int> m{{1,10},{3,30},{5,50}};
auto it = m.lower_bound(2); // 키 3을 가리킴
키가 없을 때 "정렬 상태를 유지하는 삽입 위치"를 찾는 데 유용해요. upper_bound(보다 큰 첫 위치)와 대비돼요.