I have a multimap filled with pairings. I want to iterate through a range. upper_bound does not return an iterator pointing to an element unless it find the first element whose key is greater than the value passed to upper_bound.

How can I tell if there was no value returned from upper_bound because there's nothing greater than the passed value?

At least if memory serves, if upper_bound doesn't find an element with a key larger than what you passed it, it'll return container.end(). This is fine for iterating with, as the norm for a pair of iterators is the beginning and one past the end of the range, so you can use container.end() as the end of a range without any problems.

upper_bound is actually perfect for iterating, because it points to the element just after the end of the range - just like end does. So you form your loop similarly.

for (auto it = mymap.lower_bound(start_key), end = mymap.upper_bound(end_key); it != end; ++it)

If you only want a single key, pass the same value to lower_bound and upper_bound, or use equal_range to get both at once. If the value doesn't exist in the map at all, lower_bound and upper_bound will be equal and the loop won't execute.