In C++ prime 5 Ed chapter 11. Associative containers. "Table 11.7. Operations to Find Elements in an Associative Container":
It is said: "c.equal_range(k) returns a pair of iterators denoting the elements with key k. if k is not present, both members are c.end()."
set<int> si{ 5, 7, 23, 16, 81, 24, 10};
auto it = si.equal_range(13);
cout << *it.first << " " << *it.second << endl; // 16 16
- But as you can see above
13was not found but it returns apairof iterators for elements16, 16?!
Running this program, it works as intended: It returns the end iterators.
But, if I were to check for 13, I'd get back
16, 16.According to cppreference.com
Returns a range containing all elements with the given key in the container. The range is defined by two iterators, one pointing to the first element that is not less than key and another pointing to the first element greater than key. Alternatively, the first iterator may be obtained with lower_bound(), and the second with upper_bound().16 just happens to be the first element that is not less than and also greater than 13 in your example.