std::sort with custom comparator
std::sort
accepts a functor
. This is any object that can be called (with the correct parameters). The function achieves this by using templates, like the following
template<typename Iter, typename Comp>
void sort(Iter begin, Iter end, Comp compare) { ... }
IntComparator1
, 2, and 3 are all valid functors for this comparator, since they can all be called using operator() with 2 integers.
Also like you said, the third option is indeed usually more intuitive.