1

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>?

Sergey Kalinichenko
  • 697,062
  • 78
  • 1,055
  • 1,465
SirThumbs
  • 55
  • 1
  • 4

0 Answers0