How to use lower_bound ( ) on pair class?

ref line 36

@prateek_5 waise koi way nhi hota but alternative way hai:
There is a way without constructing a temporary pair. All one needs is to define operator< between the pair and the other type. To avoid messing up with global definition of operator< for pair and int, define it for a wrapper:

template
struct Wrapper
{
T value;
};

template
bool operator<(const std::pair<T, T> & x, Wrapper value) {
return x.first < value.value;
}
template

bool operator<(Wrapper value, const std::pair<T, T> & x) {
return value.value < x.first;
}

int main()
{
// NOTE: using std::less<>, instead of the default std::less<std::pair<int, int>>
std::set<std::pair<int, int>, std::less<>> s {{1,2}, {1,3}, {4,1}, {5,1}, {5,2}};
Wrapper x{2};
auto it = s.lower_bound(x);
This is an overkill for std::pair<int, int>, but for more complicated types like std::pair<int, MyFancyClass> it can be costly to construct the smallest possible object. Also, for infinite-precision numbers, no such value exists. In that case, one must resort to the above technique. For more complicated types, it may be possible to simply overload operator<, without using a wrapper.

Note that the overloaded operators must be consistent with each other. They must be subject to the same order of elements

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.