Namespaces
Variants
Views
Actions

Constrained algorithms (since C++20)

From cppreference.com
< cpp‎ | algorithm
 
 
Algorithm library
Execution policies (C++17)
Non-modifying sequence operations
(C++11)(C++11)(C++11)
(C++17)
Modifying sequence operations
Operations on uninitialized storage
Partitioning operations
Sorting operations
(C++11)
Binary search operations
Set operations (on sorted ranges)
Heap operations
(C++11)
Minimum/maximum operations
(C++11)
(C++17)
Permutations
Numeric operations
C library
 
Constrained algorithms
Non-modifying sequence operations
                                        
                                        
Modifying sequence operations
Operations on uninitialized storage
Partitioning operations
                                                  
Sorting operations
Binary search operations
Set operations (on sorted ranges)
Heap operations
Minimum/maximum operations
Permutations
 

C++20 provides constrained versions of most algorithms in the namespace std::ranges. In these algorithms, a range can be specified as either a Iterator-Sentinel pair or as a single 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

[edit] Algorithm concepts and utilities

The header <iterator> provides a set of concepts and related utility templates 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 a Readable type
(concept) [edit]
specifies that a callable type, when invoked with the result of dereferencing a Readable type, satisfies Predicate
(concept) [edit]
specifies that a callable type, when invoked with the result of dereferencing two Readable types, satisfies Predicate
(concept) [edit]
specifies that a callable type, when invoked with the result of dereferencing two Readable types, satisfies StrictWeakOrder
(concept) [edit]
Common algorithm requirements
specifies that values may be moved from a Readable type to a Writable type
(concept) [edit]
specifies that values may be moved from a Readable type to a Writable type and that the move may be performed via an intermediate object
(concept) [edit]
specifies that values may be copied from a Readable type to a Writable type
(concept) [edit]
specifies that values may be copied from a Readable type to a Writable type and that the copy may be performed via an intermediate object
(concept) [edit]
specifies that the values referenced by two Readable types can be swapped
(concept) [edit]
specifies that the values referenced by two Readable types can be compared
(concept) [edit]
specifies the common requirements of algorithms that reorder elements in place
(concept) [edit]
specifies the requirements of algorithms that merge sorted sequences into an output sequence by copying elements
(concept) [edit]
specifies the common requirements of algorithms that permute sequences into ordered sequences
(concept) [edit]
Utilities
computes the result of invoking a callable object on the result of dereferencing some set of Readable types
(alias template) [edit]
helper template for specifying the constraints on algorithms that accept projections
(class template) [edit]

[edit] Constrained algorithms

Defined in header <algorithm>
Defined in namespace std::ranges
Non-modifying sequence operations
checks if a predicate is true for all, any or none of the elements in a range
(niebloid) [edit]
applies a function to a range of elements
(niebloid) [edit]
returns the number of elements satisfying specific criteria
(niebloid) [edit]
finds the first position where two ranges differ
(niebloid) [edit]
determines if two sets of elements are the same
(niebloid) [edit]
returns true if one range is lexicographically less than another
(niebloid) [edit]
finds the first element satisfying specific criteria
(niebloid) [edit]
finds the last sequence of elements in a certain range
(niebloid) [edit]
searches for any one of a set of elements
(niebloid) [edit]
finds the first two adjacent items that are equal (or satisfy a given predicate)
(niebloid) [edit]
searches for a range of elements
(niebloid) [edit]
searches for a number consecutive copies of an element in a range
(niebloid) [edit]
Modifying sequence operations
copies a range of elements to a new location
(niebloid) [edit]
copies a number of elements to a new location
(niebloid) [edit]
copies a range of elements in backwards order
(niebloid) [edit]
moves a range of elements to a new location
(niebloid) [edit]
moves a range of elements to a new location in backwards order
(niebloid) [edit]
assigns a range of elements a certain value
(niebloid) [edit]
assigns a value to a number of elements
(niebloid) [edit]
applies a function to a range of elements
(niebloid) [edit]
saves the result of a function in a range
(niebloid) [edit]
saves the result of N applications of a function
(niebloid) [edit]
removes elements satisfying specific criteria
(niebloid) [edit]
copies a range of elements omitting those that satisfy specific criteria
(niebloid) [edit]
replaces all values satisfying specific criteria with another value
(niebloid) [edit]
copies a range, replacing elements satisfying specific criteria with another value
(niebloid) [edit]
swaps two ranges of elements
(niebloid) [edit]
reverses the order of elements in a range
(niebloid) [edit]
creates a copy of a range that is reversed
(niebloid) [edit]
rotates the order of elements in a range
(niebloid) [edit]
copies and rotate a range of elements
(niebloid) [edit]
randomly re-orders elements in a range
(niebloid) [edit]
removes consecutive duplicate elements in a range
(niebloid) [edit]
creates a copy of some range of elements that contains no consecutive duplicates
(niebloid) [edit]
Partitioning operations
determines if the range is partitioned by the given predicate
(niebloid) [edit]
divides a range of elements into two groups
(niebloid) [edit]
copies a range dividing the elements into two groups
(niebloid) [edit]
divides elements into two groups while preserving their relative order
(niebloid) [edit]
locates the partition point of a partitioned range
(niebloid) [edit]
Sorting operations
checks whether a range is sorted into ascending order
(niebloid) [edit]
finds the largest sorted subrange
(niebloid) [edit]
sorts a range into ascending order
(niebloid) [edit]
sorts the first N elements of a range
(niebloid) [edit]
copies and partially sorts a range of elements
(niebloid) [edit]
sorts a range of elements while preserving order between equal elements
(niebloid) [edit]
partially sorts the given range making sure that it is partitioned by the given element
(niebloid) [edit]
Binary search operations (on sorted ranges)
returns an iterator to the first element not less than the given value
(niebloid) [edit]
returns an iterator to the first element greater than a certain value
(niebloid) [edit]
determines if an element exists in a certain range
(niebloid) [edit]
returns range of elements matching a specific key
(niebloid) [edit]
Set operations (on sorted ranges)
merges two sorted ranges
(niebloid) [edit]
merges two ordered ranges in-place
(niebloid) [edit]
returns true if one set is a subset of another
(niebloid) [edit]
computes the difference between two sets
(niebloid) [edit]
computes the intersection of two sets
(niebloid) [edit]
computes the symmetric difference between two sets
(niebloid) [edit]
computes the union of two sets
(niebloid) [edit]
Heap operations
checks if the given range is a max heap
(niebloid) [edit]
finds the largest subrange that is a max heap
(niebloid) [edit]
creates a max heap out of a range of elements
(niebloid) [edit]
adds an element to a max heap
(niebloid) [edit]
removes the largest element from a max heap
(niebloid) [edit]
turns a max heap into a range of elements sorted in ascending order
(niebloid) [edit]
Minimum/maximum operations
returns the greater of the given values
(niebloid) [edit]
returns the largest element in a range
(niebloid) [edit]
returns the smaller of the given values
(niebloid) [edit]
returns the smallest element in a range
(niebloid) [edit]
returns the smaller and larger of two elements
(niebloid) [edit]
returns the smallest and the largest elements in a range
(niebloid) [edit]
Permutation operations
determines if a sequence is a permutation of another sequence
(niebloid) [edit]
generates the next greater lexicographic permutation of a range of elements
(niebloid) [edit]
generates the next smaller lexicographic permutation of a range of elements
(niebloid) [edit]

[edit] Constrained uninitialized memory algorithms

Defined in header <memory>
Defined in namespace std::ranges
copies a range of objects to an uninitialized area of memory
(niebloid) [edit]
copies a number of objects to an uninitialized area of memory
(niebloid) [edit]
copies an object to an uninitialized area of memory, defined by a range
(niebloid) [edit]
copies an object to an uninitialized area of memory, defined by a start and a count
(niebloid) [edit]
moves a range of objects to an uninitialized area of memory
(niebloid) [edit]
moves a number of objects to an uninitialized area of memory
(niebloid) [edit]
constructs objects by default-initialization in an uninitialized area of memory, defined by a range
(niebloid) [edit]
constructs objects by default-initialization in an uninitialized area of memory, defined by a start and count
(niebloid) [edit]
constructs objects by value-initialization in an uninitialized area of memory, defined by a range
(niebloid) [edit]
constructs objects by value-initialization in an uninitialized area of memory, defined by a start and a count
(niebloid) [edit]
destroys an object at a given address
(niebloid) [edit]
(C++20)
destroys a range of objects
(niebloid) [edit]
(C++20)
destroys a number of objects in a range
(niebloid) [edit]