I need a binary search algorithm that is compatible with the C++ standard containers, something like std::binary_search in the standard library's <algorithm>
header, but unlike std::binary_search, I need it to return the iterator that points at the result, not a simple boolean telling me if the element exists
(On a side note, what the hell was the standard committee thinking when they defined the API for binary_search!!!)
Edit: My main concern here is that I need the speed of a binary search, so although I can find the data with other algorithms, as mentioned below, I want to take advantage that my data is already sorted to get the benefits of a binary search, not just any search.
so far lower_bound and upper_bound fail, because if the datum is missing:
//lousy pseudo code
vector(1,2,3,4,6,7,8,9,0) //notice no 5
iter = lower_bound_or_upper_bound(start,end,5)
iter != 5 && iter !=end //not returning end as usual, instead it'll return 4 or 6
Also I really doubt lower_bound and upper_bound are implemented as binary_searches, because they work just as well with unsorted data, and there is no way to provide that information through arguments or policies.
Ok as first mentioned by vividos, they DO require sorted data, which means they ARE binary searches, so the world is good again :)
Note: I'm also fine using an algorithm that doesn't belong to the std namespace as long as its compatible with containers. Likes say boost::binary_search or something