Showing content from https://en.cppreference.com/w/cpp/language/../keyword/../language/../algorithm/../algorithm.html below:
Algorithms library - cppreference.com
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 [
first,
last)
where last refers to the element past the last element to inspect or modify.
[edit] Constrained algorithms (since C++20)
C++20 provides constrained versions of most algorithms in the namespace std::ranges
. In these algorithms, a range can be specified as either an iterator-sentinel pair or as a single range
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.
[edit] Execution policies (since C++17)
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::for_each and std::for_each_n) are allowed to make arbitrary copies of elements from ranges, as long as both std::is_trivially_copy_constructible_v<T> and std::is_trivially_destructible_v<T> are true, where T
is the type of elements.
[edit] Non-modifying sequence operations [edit] Batch operations [edit] Search operations [edit] Fold operations (since C++23) [edit] Modifying sequence operations [edit] Copy operations copies a range of elements to a new location
(function template) [edit] copies a range of elements to a new location
(algorithm function object)[edit] copies a number of elements to a new location
(function template) [edit] copies a number of elements to a new location
(algorithm function object)[edit] copies a range of elements in backwards order
(function template) [edit] copies a range of elements in backwards order
(algorithm function object)[edit] moves a range of elements to a new location
(function template) [edit] moves a range of elements to a new location
(algorithm function object)[edit] moves a range of elements to a new location in backwards order
(function template) [edit] moves a range of elements to a new location in backwards order
(algorithm function object)[edit] [edit] Swap operations [edit] Transformation operations [edit] Generation operations copy-assigns the given value to every element in a range
(function template) [edit] assigns a range of elements a certain value
(algorithm function object)[edit] copy-assigns the given value to N elements in a range
(function template) [edit] assigns a value to a number of elements
(algorithm function object)[edit] assigns the results of successive function calls to every element in a range
(function template) [edit] saves the result of a function in a range
(algorithm function object)[edit] assigns the results of successive function calls to N elements in a range
(function template) [edit] saves the result of N applications of a function
(algorithm function object)[edit] [edit] Removing operations [edit] Order-changing operations [edit] Sampling operations selects N random elements from a sequence
(function template) [edit] selects N random elements from a sequence
(algorithm function object)[edit] [edit] Sorting and related operations [edit] Requirements
Some algorithms require the sequence represented by the arguments to be âsortedâ or âpartitionedâ. The behavior is undefined if the requirement is not met.
A sequence is sorted with respect to a comparator comp if for every iterator iter pointing to the sequence and every non-negative integer n such that iter + n[1] is a valid iterator pointing to an element of the sequence, comp(*(iter + n), *iter) == false[1].
(until C++20)
A sequence is sorted with respect to comp and proj for a comparator comp and projection proj if for every iterator iter pointing to the sequence and every non-negative integer n such that iter + n[1] is a valid iterator pointing to an element of the sequence, bool(std::invoke(comp, std::invoke(proj, *(iter + n)),
std::invoke(proj, *iter)))[1] is false.
A sequence is sorted with respect to a comparator comp if the sequence is sorted with respect to comp and std::identity{} (the identity projection).
(since C++20)
A sequence [
start,
finish)
is partitioned with respect to an expression f(e) if there exists an integer n such that for all i in [
â0â,
std::distance(start, finish))
, f(*(start + i))[1] is true if and only if i < n.
- â 1.0 1.1 1.2 1.3 1.4 iter + n simply means âthe result of iter being incremented n timesâ, regardless of whether iter is a random access iterator.
[edit] Partitioning operations [edit] Sorting operations [edit] Binary search operations (on partitioned ranges) returns an iterator to the first element not less than the given value
(function template) [edit] returns an iterator to the first element not less than the given value
(algorithm function object)[edit] returns an iterator to the first element greater than a certain value
(function template) [edit] returns an iterator to the first element greater than a certain value
(algorithm function object)[edit] returns range of elements matching a specific key
(function template) [edit] returns range of elements matching a specific key
(algorithm function object)[edit] determines if an element exists in a partially-ordered range
(function template) [edit] determines if an element exists in a partially-ordered range
(algorithm function object)[edit] [edit] Set operations (on sorted ranges) [edit] Merge operations (on sorted ranges) [edit] Heap operations
A random access range [
first,
last)
is a heap with respect to a comparator comp if bool(comp(first[(i - 1) / 2], first[i])) is false for all integer i in (
â0â,
last - first)
.
(until C++20)
A random access range [
first,
last)
is a heap with respect to comp and proj for a comparator comp and projection proj if bool(std::invoke(comp, std::invoke(proj, first[(i - 1) / 2]),
std::invoke(proj, first[i])) is false for all integer i in (
â0â,
last - first)
.
A random access range [
first,
last)
is a heap with respect to a comparator comp if the range is a heap with respect to comp and std::identity{} (the identity projection).
(since C++20)
A heap can be created by std::make_heap and ranges::make_heap(since C++20).
For more properties of heap, see max heap.
[edit] Minimum/maximum operations returns the greater of the given values
(function template) [edit] returns the greater of the given values
(algorithm function object)[edit] returns the largest element in a range
(function template) [edit] returns the largest element in a range
(algorithm function object)[edit] returns the smaller of the given values
(function template) [edit] returns the smaller of the given values
(algorithm function object)[edit] returns the smallest element in a range
(function template) [edit] returns the smallest element in a range
(algorithm function object)[edit] returns the smaller and larger of two elements
(function template) [edit] returns the smaller and larger of two elements
(algorithm function object)[edit] returns the smallest and the largest elements in a range
(function template) [edit] returns the smallest and the largest elements in a range
(algorithm function object)[edit] clamps a value between a pair of boundary values
(function template) [edit] clamps a value between a pair of boundary values
(algorithm function object)[edit] [edit] Lexicographical comparison operations [edit] Permutation operations generates the next greater lexicographic permutation of a range of elements
(function template) [edit] generates the next greater lexicographic permutation of a range of elements
(algorithm function object)[edit] generates the next smaller lexicographic permutation of a range of elements
(function template) [edit] generates the next smaller lexicographic permutation of a range of elements
(algorithm function object)[edit] determines if a sequence is a permutation of another sequence
(function template) [edit] determines if a sequence is a permutation of another sequence
(algorithm function object)[edit] [edit] Numeric operations [edit] Operations on uninitialized memory copies a range of objects to an uninitialized area of memory
(function template) [edit] copies a range of objects to an uninitialized area of memory
(algorithm function object)[edit] copies a number of objects to an uninitialized area of memory
(function template) [edit] copies a number of objects to an uninitialized area of memory
(algorithm function object)[edit] copies an object to an uninitialized area of memory, defined by a range
(function template) [edit] copies an object to an uninitialized area of memory, defined by a range
(algorithm function object)[edit] copies an object to an uninitialized area of memory, defined by a start and a count
(function template) [edit] copies an object to an uninitialized area of memory, defined by a start and a count
(algorithm function object)[edit] moves a range of objects to an uninitialized area of memory
(function template) [edit] moves a range of objects to an uninitialized area of memory
(algorithm function object)[edit] moves a number of objects to an uninitialized area of memory
(function template) [edit] moves a number of objects to an uninitialized area of memory
(algorithm function object)[edit] constructs objects by default-initialization in an uninitialized area of memory, defined by a range
(function template) [edit] constructs objects by default-initialization in an uninitialized area of memory, defined by a range
(algorithm function object)[edit] constructs objects by default-initialization in an uninitialized area of memory, defined by a start and a count
(function template) [edit] constructs objects by default-initialization in an uninitialized area of memory, defined by a start and count
(algorithm function object)[edit] constructs objects by value-initialization in an uninitialized area of memory, defined by a range
(function template) [edit] constructs objects by value-initialization in an uninitialized area of memory, defined by a range
(algorithm function object)[edit] constructs objects by value-initialization in an uninitialized area of memory, defined by a start and a count
(function template) [edit] constructs objects by value-initialization in an uninitialized area of memory, defined by a start and a count
(algorithm function object)[edit] destroys a range of objects
(function template) [edit] destroys a range of objects
(algorithm function object)[edit] destroys a number of objects in a range
(function template) [edit] destroys a number of objects in a range
(algorithm function object)[edit] destroys an object at a given address
(function template) [edit] destroys an object at a given address
(algorithm function object)[edit] creates an object at a given address
(function template) [edit] creates an object at a given address
(algorithm function object)[edit] [edit] Random number generation (since C++26) [edit] Notes [edit] C library sorts a range of elements with unspecified type
(function) [edit] searches an array for an element of unspecified type
(function) [edit] [edit] Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR Applied to Behavior as published Correct behavior LWG 193 C++98 heap required *first to be the largest element there can be elements
equal to *first LWG 2150 C++98 the definition of a sorted sequence was incorrect corrected LWG 2166 C++98 the heap requirement did not match the
definition of max heap closely enough requirement improved [edit] See also
RetroSearch is an open source project built by @garambo
| Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4