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