1

I was looking at the std::greater function the other day and was very confused as to why they implemented it as a functor. Were they just showing off their c++ skills or was there an actual design decision that led to that?

  • 2
    Do you mean *functor*? As opposed to implementing it as, say, a lambda or plain templated function? I don't think I've ever heard anything in C++ described as a *functoid*. If it's just "why functor instead of function?" [that's been answered](https://stackoverflow.com/q/6451866/364696). If it's "why functor instead of lambda?", [that's also been answered](https://stackoverflow.com/q/27256062/364696) ([more than once](https://stackoverflow.com/q/4686507/364696)). – ShadowRanger Oct 23 '20 at 19:39
  • Yes, I just edited the question. Sorry about that. – Jack123 Sparrow Oct 23 '20 at 19:42
  • I do not think duplicates answer the question - the linked questions explains why someone might want to implement their comparator as a functor rather than a function, but not why `std::greater` is a functor. – SergeyA Oct 23 '20 at 20:35
  • 2
    Before C++11 there were no lambdas, the only way to pass a function *with associated state* would be to capture the state in an instance of a `class`. – G. Sliepen Oct 23 '20 at 20:40

0 Answers0