equal_range
The expected behavior, does not make sense to me…
If we search for value 4, then the result is an empty sub-range because there is no such element in the input range. In this case, the first iterator returned points to 5 because this is the first element not less than 4; the second iterator points also to the element 5 because this is the first element greater than 4. - Understanding equal_range / cppreference.com
What I would expect is more something in the line of this:
if you want the closest entry, you need to check both the returned entry and the one before and compare the differences.
which should translate more or less to this: for [10,13,17]
- when asking for 13, ok got [13,13[
- when asking for 14, then got [13,17[
- when asking for 18, then got [17,end[
- when asking for 9, then got [10,10[ - which is less than ideal, but work in my specific case
Written on January 18, 2022, Last update on January 18, 2022
c++
search