The <functional>
header in the C++ STL provides several operator classes. I've been told I should use these operator classes rather than a class' equivalent operatorXX
. Why is that the case? What's the issue with using operator<
directly?
For instance, say we have a std::vector<string> v
that we would like to sort. Using the sort()
function, I could write the following:
sort(v.begin(), v.end(), operator<);
But I've been told that it's better to write
sort(v.begin(), v.end(), less<string>())
What is the advantage of using these operator classes defined in <functional>
?