cpp/algorithm

The algorithms library defines functions for a variety of purposes (e.g. searching, sorting, counting, manipulating) that operate on ranges of elements. Note that a range is defined as where  refers to the element past the last element to inspect or modify.

{{rrev|since=c++20|

C++20 provides constrained versions of most algorithms in the namespace. In these algorithms, a range can be specified as either an iterator-sentinel pair or as a single argument, and projections and pointer-to-member callables are supported. Additionally, the return types of most algorithms have been changed to return all potentially useful information computed during the execution of the algorithm.

}}

{{rrev|since=c++17|

Execution policies
Most algorithms have overloads that accept execution policies. The standard library algorithms support several execution policies, and the library provides corresponding execution policy types and objects. Users may select an execution policy statically by invoking a parallel algorithm with an execution policy object of the corresponding type.

Standard library implementations (but not the users) may define additional execution policies as an extension. The semantics of parallel algorithms invoked with an execution policy object of implementation-defined type is implementation-defined.

Parallel version of algorithms (except for std and std) are allowed to make arbitrary copies of elements from ranges, as long as both and  are, where  is the type of elements.

}}