Pairs support assignment and swap operations that work element-wise. Assignment: pair<int, int> p1{1, 2}, p2{3, 4}; p1 = p2; Now p1 is {3, 4}. Both .first and .second are copied. Swap: swap(p1, p2); Exchanges both elements of both pairs.
This is more efficient than manual swapping with a temporary. You can also assign pairs of different but compatible types: pair<double, double> pd = pi; where pi is pair<int, int>. The ints convert to doubles.