Constrained algorithms (since C++20)
From cppreference.com
C++20 provides constrained versions of most algorithms in the namespace std::ranges
. In these algorithms, a range can be specified as either a [[cpp/unrecognized concept/Iterator|Iterator
]]-[[cpp/unrecognized concept/Sentinel|Sentinel
]] pair or as a single [[cpp/unrecognized concept/Range|Range
]] argument, and projections and pointer-to-member callables are supported. Additionally, the return type of most algorithms have been changed to return all potentially useful information computed during the execution of the algorithm.
Contents |
Algorithm concepts and utilities
The header <iterator> provides a set of concepts and related utility designed to ease constraining common algorithm operations.
Defined in header
<iterator> | |
Defined in namespace
std | |
Indirect callable concepts | |
specifies that a callable type can be invoked with the result of dereferencing an indirectly_readable type (concept) | |
(C++20) |
specifies that a callable type, when invoked with the result of dereferencing an indirectly_readable type, satisfies predicate (concept) |
specifies that a callable type, when invoked with the result of dereferencing two [[cpp/unrecognized concept/readable|readable ]] types, satisfies predicate (concept) | |
(C++20) |
specifies that a callable type, when invoked with the result of dereferencing two indirectly_readable types, satisfies strict_weak_order (concept) |
Common algorithm requirements | |
(C++20) |
specifies that values may be moved from an indirectly_readable type to an indirectly_writable type (concept) |
(C++20) |
specifies that values may be moved from an indirectly_readable type to an indirectly_writable type and that the move may be performed via an intermediate object (concept) |
(C++20) |
specifies that values may be copied from an indirectly_readable type to an indirectly_writable type (concept) |
(C++20) |
specifies that values may be copied from an indirectly_readable type to an indirectly_writable type and that the copy may be performed via an intermediate object (concept) |
(C++20) |
specifies that the values referenced by two indirectly_readable types can be swapped (concept) |
(C++20) |
specifies that the values referenced by two indirectly_readable types can be compared (concept) |
(C++20) |
specifies the common requirements of algorithms that reorder elements in place (concept) |
(C++20) |
specifies the requirements of algorithms that merge sorted sequences into an output sequence by copying elements (concept) |
(C++20) |
specifies the common requirements of algorithms that permute sequences into ordered sequences (concept) |
Utilities | |
(C++20) |
computes the result of invoking a callable object on the result of dereferencing some set of indirectly_readable types(alias template) |
(C++20) |
helper template for specifying the constraints on algorithms that accept projections (class template) |
Constrained algorithms
Defined in header
<algorithm> | |
Defined in namespace
std::ranges | |
Non-modifying sequence operations | |
(C++20)(C++20)(C++20) |
checks if a predicate is true for all, any or none of the elements in a range (niebloid) |
(C++20) |
applies a function to a range of elements (niebloid) |
(C++20)(C++20) |
returns the number of elements satisfying specific criteria (niebloid) |
(C++20) |
finds the first position where two ranges differ (niebloid) |
(C++20) |
determines if two sets of elements are the same (niebloid) |
returns true if one range is lexicographically less than another (niebloid) | |
(C++20)(C++20)(C++20) |
finds the first element satisfying specific criteria (niebloid) |
(C++20) |
finds the last sequence of elements in a certain range (niebloid) |
(C++20) |
searches for any one of a set of elements (niebloid) |
(C++20) |
finds the first two adjacent items that are equal (or satisfy a given predicate) (niebloid) |
(C++20) |
searches for the first occurrence of a range of elements (niebloid) |
(C++20) |
searches for the first occurrence of a number consecutive copies of an element in a range (niebloid) |
Modifying sequence operations | |
(C++20)(C++20) |
copies a range of elements to a new location (niebloid) |
(C++20) |
copies a number of elements to a new location (niebloid) |
(C++20) |
copies a range of elements in backwards order (niebloid) |
(C++20) |
moves a range of elements to a new location (niebloid) |
(C++20) |
moves a range of elements to a new location in backwards order (niebloid) |
(C++20) |
assigns a range of elements a certain value (niebloid) |
(C++20) |
assigns a value to a number of elements (niebloid) |
(C++20) |
applies a function to a range of elements (niebloid) |
(C++20) |
saves the result of a function in a range (niebloid) |
(C++20) |
saves the result of N applications of a function (niebloid) |
(C++20)(C++20) |
removes elements satisfying specific criteria (niebloid) |
(C++20)(C++20) |
copies a range of elements omitting those that satisfy specific criteria (niebloid) |
(C++20)(C++20) |
replaces all values satisfying specific criteria with another value (niebloid) |
(C++20)(C++20) |
copies a range, replacing elements satisfying specific criteria with another value (niebloid) |
(C++20) |
swaps two ranges of elements (niebloid) |
(C++20) |
reverses the order of elements in a range (niebloid) |
(C++20) |
creates a copy of a range that is reversed (niebloid) |
(C++20) |
rotates the order of elements in a range (niebloid) |
(C++20) |
copies and rotate a range of elements (niebloid) |
(C++20) |
randomly re-orders elements in a range (niebloid) |
(C++20) |
removes consecutive duplicate elements in a range (niebloid) |
(C++20) |
creates a copy of some range of elements that contains no consecutive duplicates (niebloid) |
Partitioning operations | |
(C++20) |
determines if the range is partitioned by the given predicate (niebloid) |
(C++20) |
divides a range of elements into two groups (niebloid) |
(C++20) |
copies a range dividing the elements into two groups (niebloid) |
(C++20) |
divides elements into two groups while preserving their relative order (niebloid) |
(C++20) |
locates the partition point of a partitioned range (niebloid) |
Sorting operations | |
(C++20) |
checks whether a range is sorted into ascending order (niebloid) |
(C++20) |
finds the largest sorted subrange (niebloid) |
(C++20) |
sorts a range into ascending order (niebloid) |
(C++20) |
sorts the first N elements of a range (niebloid) |
(C++20) |
copies and partially sorts a range of elements (niebloid) |
(C++20) |
sorts a range of elements while preserving order between equal elements (niebloid) |
(C++20) |
partially sorts the given range making sure that it is partitioned by the given element (niebloid) |
Binary search operations (on sorted ranges) | |
(C++20) |
returns an iterator to the first element not less than the given value (niebloid) |
(C++20) |
returns an iterator to the first element greater than a certain value (niebloid) |
(C++20) |
determines if an element exists in a partially-ordered range (niebloid) |
(C++20) |
returns range of elements matching a specific key (niebloid) |
Set operations (on sorted ranges) | |
(C++20) |
merges two sorted ranges (niebloid) |
(C++20) |
merges two ordered ranges in-place (niebloid) |
(C++20) |
returns true if one sequence is a subsequence of another (niebloid) |
(C++20) |
computes the difference between two sets (niebloid) |
(C++20) |
computes the intersection of two sets (niebloid) |
computes the symmetric difference between two sets (niebloid) | |
(C++20) |
computes the union of two sets (niebloid) |
Heap operations | |
(C++20) |
checks if the given range is a max heap (niebloid) |
(C++20) |
finds the largest subrange that is a max heap (niebloid) |
(C++20) |
creates a max heap out of a range of elements (niebloid) |
(C++20) |
adds an element to a max heap (niebloid) |
(C++20) |
removes the largest element from a max heap (niebloid) |
(C++20) |
turns a max heap into a range of elements sorted in ascending order (niebloid) |
Minimum/maximum operations | |
(C++20) |
returns the greater of the given values (niebloid) |
(C++20) |
returns the largest element in a range (niebloid) |
(C++20) |
returns the smaller of the given values (niebloid) |
(C++20) |
returns the smallest element in a range (niebloid) |
(C++20) |
returns the smaller and larger of two elements (niebloid) |
(C++20) |
returns the smallest and the largest elements in a range (niebloid) |
Permutation operations | |
(C++20) |
determines if a sequence is a permutation of another sequence (niebloid) |
(C++20) |
generates the next greater lexicographic permutation of a range of elements (niebloid) |
(C++20) |
generates the next smaller lexicographic permutation of a range of elements (niebloid) |