The recommended way (eg: Sorting a vector in descending order) of sorting a container in reverse seems to be:
std::sort(numbers.begin(), numbers.end(), std::greater<int>());
I understand the third argument is a function or a functor that helps sort() make the comparisons, and that std::greater is a template functor, but I don't understand what's going on here. My C++ is quite rusty so please bear with me if these are stupid questions: Why are there parentheses after std::greater<int>
there? Are we creating a new std::greater
object here? In that case, why don't we need the new
keyword here?