All Ordered Bound Operations
All Ordered Bound Operations
A compact scan page for lower_bound, upper_bound, equal_range, and related ordered-lookup operations across sorted ranges and ordered containers.
All Ordered Bound Operations
A compact scan page for lower_bound, upper_bound, equal_range, and related ordered-lookup operations across sorted ranges and ordered containers.
Use reference pages to confirm names, categories, nearby facilities, and the constraints that matter before writing or reviewing code.
lower_boundupper_boundequal_rangebinary_searchmap and set<algorithm> sorted-range algorithmslower_bound: first element not less than the keyupper_bound: first element greater than the keyequal_range: pair of lower/upper bounds for equivalent valuesequal_range is often the clearest choice.#include <map>
#include <string>
int main() {
std::map<std::string, int> counts{std::pair{"Ada", 1}, std::pair{"Bjarne", 2}};
auto [it, inserted] = counts.insert({"Grace", 3});
return inserted ? it->second : 1;
}