Algorithm concept

Back to PastelSys

An algorithm, as a concept, is an object which encapsulates a generic algorithm.

Motivation

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.

Learn more

Predicate concept

Range algorithm concept

Files

Algorithm concept

algorithm_concept.h