Pairs have a default comparison that enables sorting. The comparison is lexicographic: first compare by .first, then by .second if the first values are equal. Example: sorting [(3,1), (1,2), (1,1)] gives [(1,1), (1,2), (3,1)].
The pairs with first=1 come before first=3. Among those, (1,1) comes before (1,2) because 1 < 2. To sort a vector of pairs: sort(vec.begin(), vec.end()); This uses the default comparison.
If you want a different order, provide a custom comparator. Custom sort example: sort by second value: sort(vec.begin(), vec.end(), [](auto& a, auto& b) { return a.second < b.second; });