Add a function object to compare the first or second component of a std::pair.

Replace instances of this scattered around the code base.