An algorithm object is an object which encapsulates a generic algorithm. The corresponding concept is called an algorithm.
In generic programming, it is often desirable to parametrize an algorithm
by sub-algorithms. For example, the std::sort()
algorithm in the C++
Standard Library takes in an object which defines the ordering to use.
Compared to a usual functor, an algorithm object is different in that
usually the functor’s operator()
is not a function template. For
example, while normally you would pass a std::less<int>()
to the
std::sort()
, with algorithm objects you would pass a LessThan()
,
which encapsulates a less-than comparison for all types.