Lower_bound and Upper_bound on vector of pairs

How lower_bound and upper_bound function works on vector of pairs in c++ and how can i modify it!

1 Like

they work the same on normal int vectors except here , it first compared the first element and then the second element.
for custom comparator, you use lambda function and do something like this

auto it = std::lower_bound(vec.begin(), vec.end(), low_val, 
    [](myPair lhs, myPair rhs) -> bool { return lhs.second < rhs.second; });

here low_val is also pair that you searching for

refer follow this link