How does the < and > operators work on pair when first value of pair is equal? I have read 2 different concepts on this which has confused me.
eg.
pair<int,int> p1(5,10);
pair<int,int> p2(5,12);
What should be the answer of p1 > p2 ?
How does the < and > operators work on pair when first value of pair is equal? I have read 2 different concepts on this which has confused me.
eg.
pair<int,int> p1(5,10);
pair<int,int> p2(5,12);
What should be the answer of p1 > p2 ?
As usual the answer is in the docs:
Compares lhs and rhs lexicographically by operator<, that is, compares the first elements and only if they are equivalent, compares the second elements.
Return value:
operator<
If
lhs.first<rhs.first
, returnstrue
. Otherwise, ifrhs.first<lhs.first
, returnsfalse
. Otherwise, iflhs.second<rhs.second
, returnstrue
. Otherwise, returnsfalse
operator>
rhs < lhs