lower_bound — first >= value. upper_bound — first > value.
1std::vector<int> v = {1, 2, 2, 2, 3, 4};23// lower_bound — first >= 24auto lb = std::lower_bound(v.begin(), v.end(), 2);5// Points to first 2 (index 1)67// upper_bound — first > 28auto ub = std::upper_bound(v.begin(), v.end(), 2);9// Points to 3 (index 4)1011// Range of 2s12auto range = std::equal_range(v.begin(), v.end(), 2);13// range.first = lb, range.second = ub14std::cout << std::distance(range.first, range.second);15// 3 (three 2s)
Use cases: