I need to find the nearest keys in my map in a given range [x,y]
. I am trying below
std::map<int, char> m{ {-2,'B'}, {1, 'C'}, {2, 'A'}};
auto itCurrent = m.lower_bound(-3);
auto itNext = m.upper_bound(-3);
auto it1 = m.lower_bound(3);
auto it2 = m.upper_bound(3);
I was hoping to get -2
and 2
by using lower_bound
and uppper_bound
around the enquiry boundary [-3,3]
. it1
and it2
are returning end
while itCurrent
and itNext
return -2
.
How do I get -2 and 2
as result?