How to find an element in a specified range in std::map?
You can use std::lower_bound
, std::upper_bound
or std::equal_range
for that as std::map
iterators and data in the map satisfy the requirement for those functions, though you should be aware that it will be less efficient than std::map::find()
due to linear iterator increments.
From std::lower_bound
documentation
The number of comparisons performed is logarithmic in the distance between first and last (At most log 2(last - first) + O(1) comparisons). However, for non-LegacyRandomAccessIterators, the number of iterator increments is linear.
emphasis is mine.