You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Find the next element greater/equal than/to (>=) k
map<int,int>::iterator it = m.lower_bound(k);
// if (it==m.end()): not found// else result: it->first
Find the next element greater than (>) k
map<int,int>::iterator it = m.upper_bound(k);
// if (it==m.end()): not found// else result: it->first
Find the next element smaller than (<) k
map<int,int>::iterator it = --m.lower_bound(k);
// if (it==m.begin()): not found// else result: it->first
Template
template < typename Key, typename Value, typename Compare, typename Alloc >
autolowerEntry(std::map<Key, Value, Compare, Alloc> map, Key key) -> decltype(map.begin()) {
auto iter = map.lower_bound(key); // find the first element to go at or after keyif(iter == map.begin()) // all elements go after keyreturn map.end(); // signals that no lowerEntry could be foundreturn --iter; // pre-decrement to return an iterator to the element before iter
}