But passing function has shortcomings 1) Can’t be inline. 2) sometimes
It can’t be compile due to different compiler implementation. 3)
You can’t adapt or custom it. So STL invented a functor(function
object). It is class or structure objects for which the () operator is
overloaded.
You can use struct or class. If you want to have a private customized value,
you have to use class to build a functor. Such as cutoff value in below code.
In previous example, you can see advantage of usage less_than_value.
You can inherit from template unary_function when you declare
a functor, then you functor is adaptable by bind1().
But if you want to have a cutoff value, You can use class to make
cutoff value as private.
set or map are template class. So it only accept type, not function, If
you want to give set or map a customized compare function, you have
to use functor to define a type.
Sometimes, you don’t want to reuse this functor which will cause you write
clutter code, so C++14 introduce lambda. Detail can be seen in C++ 11
New features.