0% found this document useful (0 votes)
7 views14 pages

Algorithms Library

The algorithms library in C++ provides functions for various operations on ranges of elements, including searching, sorting, and manipulating. C++20 introduces constrained algorithms and execution policies, allowing for more flexible and efficient operations. The library also includes numerous algorithms for non-modifying, modifying, and order-changing operations, among others.

Uploaded by

Priyanka Singh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views14 pages

Algorithms Library

The algorithms library in C++ provides functions for various operations on ranges of elements, including searching, sorting, and manipulating. C++20 introduces constrained algorithms and execution policies, allowing for more flexible and efficient operations. The library also includes numerous algorithms for non-modifying, modifying, and order-changing operations, among others.

Uploaded by

Priyanka Singh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

14/10/2024, 15:09 Algorithms library - cppreference.

com

Algorithms library
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.

Constrained algorithms

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
(since C++20)
have been changed to return all potentially useful information computed during the execution of the algorithm.

std::vector<int> v {7, 1, 4, 0, -1};


std::ranges::sort(v); // constrained algorithm

(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::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.
Defined in header <execution>
Defined in namespace std::execution
sequenced_policy (C++17)
parallel_policy (C++17) execution policy types
parallel_unsequenced_policy (C++17) (class)
unsequenced_policy (C++20)

seq (C++17)
par (C++17) global execution policy objects
par_unseq (C++17) (constant)
unseq (C++20)
Defined in namespace std
test whether a class represents an execution policy
is_execution_policy (C++17)
(class template)

[Link] 1/14
14/10/2024, 15:09 Algorithms library - [Link]
Feature-test macro Value Std Feature
__cpp_lib_parallel_algorithm 201603L (C++17) Parallel algorithms
201603L (C++17) Execution policies
__cpp_lib_execution
201902L (C++20) std::execution::unsequenced_policy

Non-modifying sequence operations

Batch operations

Defined in header <algorithm>


applies a function to a range of elements
for_each
(function template)
applies a function to a range of elements
ranges::for_each (C++20)
(niebloid)
applies a function object to the first N elements of a sequence
for_each_n (C++17) (function template)
applies a function object to the first N elements of a sequence
ranges::for_each_n (C++20)
(niebloid)

Search operations

Defined in header <algorithm>


all_of (C++11)
checks if a predicate is true for all, any or none of the elements in a range
any_of (C++11)
(function template)
none_of (C++11)
ranges::all_of (C++20)
checks if a predicate is true for all, any or none of the elements in a range
ranges::any_of (C++20)
(niebloid)
ranges::none_of (C++20)
ranges::contains (C++23) checks if the range contains the given element or subrange
ranges::contains_subrange (C++23) (niebloid)
find
finds the first element satisfying specific criteria
find_if
(function template)
find_if_not (C++11)
ranges::find (C++20)
finds the first element satisfying specific criteria
ranges::find_if (C++20)
(niebloid)
ranges::find_if_not (C++20)
ranges::find_last (C++23)
finds the last element satisfying specific criteria
ranges::find_last_if (C++23)
(niebloid)
ranges::find_last_if_not (C++23)
finds the last sequence of elements in a certain range
find_end
(function template)
finds the last sequence of elements in a certain range
ranges::find_end (C++20)
(niebloid)
searches for any one of a set of elements
find_first_of
(function template)

[Link] 2/14
14/10/2024, 15:09 Algorithms library - [Link]
searches for any one of a set of elements
ranges::find_first_of (C++20)
(niebloid)
finds the first two adjacent items that are equal (or satisfy a given predicate)
adjacent_find
(function template)
finds the first two adjacent items that are equal (or satisfy a given predicate)
ranges::adjacent_find (C++20)
(niebloid)
count returns the number of elements satisfying specific criteria
count_if (function template)

ranges::count (C++20) returns the number of elements satisfying specific criteria


ranges::count_if (C++20) (niebloid)

finds the first position where two ranges differ


mismatch
(function template)
finds the first position where two ranges differ
ranges::mismatch (C++20)
(niebloid)
determines if two sets of elements are the same
equal
(function template)
determines if two sets of elements are the same
ranges::equal (C++20)
(niebloid)
searches for the first occurrence of a range of elements
search
(function template)
searches for the first occurrence of a range of elements
ranges::search (C++20)
(niebloid)
searches for the first occurrence of a number consecutive copies of an
search_n element in a range
(function template)
searches for the first occurrence of a number consecutive copies of an
ranges::search_n (C++20) element in a range
(niebloid)
checks whether a range starts with another range
ranges::starts_with (C++23)
(niebloid)
checks whether a range ends with another range
ranges::ends_with (C++23)
(niebloid)

Fold operations

Defined in header <algorithm>


left-folds a range of elements
ranges::fold_left (C++23)
(niebloid)
left-folds a range of elements using the first element as an initial
ranges::fold_left_first (C++23) value
(niebloid)
right-folds a range of elements
ranges::fold_right (C++23)
(niebloid)
right-folds a range of elements using the last element as an initial
ranges::fold_right_last (C++23) value
(niebloid)
left-folds a range of elements, and returns a pair (iterator, value)
ranges::fold_left_with_iter (C++23)
(niebloid)
left-folds a range of elements using the first element as an initial
ranges::fold_left_first_with_iter (C++23) value, and returns a pair (iterator, optional)
(niebloid)

[Link] 3/14
14/10/2024, 15:09 Algorithms library - [Link]

Modifying sequence operations

Copy operations

Defined in header <algorithm>


copy copies a range of elements to a new location
copy_if (C++11) (function template)

ranges::copy (C++20) copies a range of elements to a new location


ranges::copy_if (C++20) (niebloid)

copies a number of elements to a new location


copy_n (C++11)
(function template)
copies a number of elements to a new location
ranges::copy_n (C++20)
(niebloid)
copies a range of elements in backwards order
copy_backward
(function template)
copies a range of elements in backwards order
ranges::copy_backward (C++20)
(niebloid)
moves a range of elements to a new location
move (C++11)
(function template)
moves a range of elements to a new location
ranges::move (C++20)
(niebloid)
moves a range of elements to a new location in backwards order
move_backward (C++11)
(function template)
moves a range of elements to a new location in backwards order
ranges::move_backward (C++20)
(niebloid)

Swap operations

Defined in header <algorithm> (until C++11)


Defined in header <utility> (since C++11)
Defined in header <string_view>
swaps the values of two objects
swap
(function template)
Defined in header <algorithm>
swaps two ranges of elements
swap_ranges (function template)
swaps two ranges of elements
ranges::swap_ranges (C++20)
(niebloid)
swaps the elements pointed to by two iterators
iter_swap
(function template)

Transformation operations

Defined in header <algorithm>


applies a function to a range of elements, storing results in a destination range
transform (function template)
applies a function to a range of elements
ranges::transform (C++20)
(niebloid)

replace replaces all values satisfying specific criteria with another value
replace_if (function template)

[Link] 4/14
14/10/2024, 15:09 Algorithms library - [Link]
ranges::replace (C++20) replaces all values satisfying specific criteria with another value
ranges::replace_if (C++20) (niebloid)

replace_copy copies a range, replacing elements satisfying specific criteria with another value
replace_copy_if (function template)

ranges::replace_copy (C++20) copies a range, replacing elements satisfying specific criteria with another value
ranges::replace_copy_if (C++20) (niebloid)

Generation operations

Defined in header <algorithm>


copy-assigns the given value to every element in a range
fill
(function template)
assigns a range of elements a certain value
ranges::fill (C++20)
(niebloid)
copy-assigns the given value to N elements in a range
fill_n (function template)
assigns a value to a number of elements
ranges::fill_n (C++20)
(niebloid)
assigns the results of successive function calls to every element in a range
generate
(function template)
saves the result of a function in a range
ranges::generate (C++20)
(niebloid)
assigns the results of successive function calls to N elements in a range
generate_n
(function template)
saves the result of N applications of a function
ranges::generate_n (C++20)
(niebloid)

Removing operations

Defined in header <algorithm>


remove removes elements satisfying specific criteria
remove_if (function template)

ranges::remove (C++20) removes elements satisfying specific criteria


ranges::remove_if (C++20) (niebloid)

remove_copy copies a range of elements omitting those that satisfy specific criteria
remove_copy_if (function template)

ranges::remove_copy (C++20) copies a range of elements omitting those that satisfy specific criteria
ranges::remove_copy_if (C++20) (niebloid)
removes consecutive duplicate elements in a range
unique
(function template)
removes consecutive duplicate elements in a range
ranges::unique (C++20)
(niebloid)
creates a copy of some range of elements that contains no consecutive duplicates
unique_copy
(function template)
creates a copy of some range of elements that contains no consecutive duplicates
ranges::unique_copy (C++20)
(niebloid)

Order-changing operations

Defined in header <algorithm>

[Link] 5/14
14/10/2024, 15:09 Algorithms library - [Link]
reverses the order of elements in a range
reverse
(function template)
reverses the order of elements in a range
ranges::reverse (C++20)
(niebloid)
creates a copy of a range that is reversed
reverse_copy
(function template)
creates a copy of a range that is reversed
ranges::reverse_copy (C++20)
(niebloid)
rotates the order of elements in a range
rotate
(function template)
rotates the order of elements in a range
ranges::rotate (C++20) (niebloid)
copies and rotate a range of elements
rotate_copy
(function template)
copies and rotate a range of elements
ranges::rotate_copy (C++20)
(niebloid)
shift_left shifts elements in a range
(C++20)
shift_right (function template)

random_shuffle (until C++17) randomly re-orders elements in a range


shuffle (C++11) (function template)

randomly re-orders elements in a range


ranges::shuffle (C++20)
(niebloid)

ranges::shift_left shifts elements in a range


(C++23)
ranges::shift_right (niebloid)

Sampling operations

Defined in header <algorithm>


selects N random elements from a sequence
sample (C++17)
(function template)
selects N random elements from a sequence
ranges::sample (C++20) (niebloid)

Sorting and related operations

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
(until C++20)
iter + n [1] is a valid iterator pointing to an element of the sequence, comp(*(iter + n), *iter) == false [1].

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)), (since C++20)
[1]
std::invoke(proj, *iter))) 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).

[Link] 6/14
14/10/2024, 15:09 Algorithms library - [Link]
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. ↑ 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.

Partitioning operations

Defined in header <algorithm>


determines if the range is partitioned by the given predicate
is_partitioned (C++11)
(function template)
determines if the range is partitioned by the given predicate
ranges::is_partitioned (C++20)
(niebloid)
divides a range of elements into two groups
partition
(function template)
divides a range of elements into two groups
ranges::partition (C++20)
(niebloid)
copies a range dividing the elements into two groups
partition_copy (C++11)
(function template)
copies a range dividing the elements into two groups
ranges::partition_copy (C++20)
(niebloid)
divides elements into two groups while preserving their relative order
stable_partition
(function template)
divides elements into two groups while preserving their relative order
ranges::stable_partition (C++20) (niebloid)
locates the partition point of a partitioned range
partition_point (C++11)
(function template)
locates the partition point of a partitioned range
ranges::partition_point (C++20)
(niebloid)

Sorting operations

Defined in header <algorithm>


sorts a range into ascending order
sort
(function template)
sorts a range into ascending order
ranges::sort (C++20)
(niebloid)
sorts a range of elements while preserving order between equal elements
stable_sort
(function template)
sorts a range of elements while preserving order between equal elements
ranges::stable_sort (C++20)
(niebloid)
sorts the first N elements of a range
partial_sort
(function template)
sorts the first N elements of a range
ranges::partial_sort (C++20)
(niebloid)
copies and partially sorts a range of elements
partial_sort_copy
(function template)
copies and partially sorts a range of elements
ranges::partial_sort_copy (C++20)
(niebloid)
checks whether a range is sorted into ascending order
is_sorted (C++11)
(function template)
checks whether a range is sorted into ascending order
ranges::is_sorted (C++20)
(niebloid)

[Link] 7/14
14/10/2024, 15:09 Algorithms library - [Link]
finds the largest sorted subrange
is_sorted_until (C++11)
(function template)
finds the largest sorted subrange
ranges::is_sorted_until (C++20)
(niebloid)
partially sorts the given range making sure that it is partitioned by the given
nth_element element
(function template)
partially sorts the given range making sure that it is partitioned by the given
ranges::nth_element (C++20) element
(niebloid)

Binary search operations (on partitioned ranges)

Defined in header <algorithm>


returns an iterator to the first element not less than the given value
lower_bound
(function template)
returns an iterator to the first element not less than the given value
ranges::lower_bound (C++20)
(niebloid)
returns an iterator to the first element greater than a certain value
upper_bound
(function template)
returns an iterator to the first element greater than a certain value
ranges::upper_bound (C++20) (niebloid)
returns range of elements matching a specific key
equal_range
(function template)
returns range of elements matching a specific key
ranges::equal_range (C++20)
(niebloid)
determines if an element exists in a partially-ordered range
binary_search
(function template)
determines if an element exists in a partially-ordered range
ranges::binary_search (C++20)
(niebloid)

Set operations (on sorted ranges)

Defined in header <algorithm>


returns true if one sequence is a subsequence of another
includes
(function template)
returns true if one sequence is a subsequence of another
ranges::includes (C++20)
(niebloid)
computes the union of two sets
set_union
(function template)
computes the union of two sets
ranges::set_union (C++20)
(niebloid)
computes the intersection of two sets
set_intersection
(function template)
computes the intersection of two sets
ranges::set_intersection (C++20)
(niebloid)
computes the difference between two sets
set_difference
(function template)
computes the difference between two sets
ranges::set_difference (C++20)
(niebloid)
computes the symmetric difference between two sets
set_symmetric_difference
(function template)

[Link] 8/14
14/10/2024, 15:09 Algorithms library - [Link]
computes the symmetric difference between two sets
ranges::set_symmetric_difference (C++20)
(niebloid)

Merge operations (on sorted ranges)

Defined in header <algorithm>


merges two sorted ranges
merge
(function template)
merges two sorted ranges
ranges::merge (C++20)
(niebloid)
merges two ordered ranges in-place
inplace_merge
(function template)
merges two ordered ranges in-place
ranges::inplace_merge (C++20)
(niebloid)

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
(until C++20)
integer i in ( ​
0​, last - first ).

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 ). (since C++20)

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).

A heap can be created by std::make_heap and ranges::make_heap(since C++20) .

For more properties of heap, see max heap .

Defined in header <algorithm>


adds an element to a max heap
push_heap
(function template)
adds an element to a max heap
ranges::push_heap (C++20)
(niebloid)
removes the largest element from a max heap
pop_heap
(function template)
removes the largest element from a max heap
ranges::pop_heap (C++20) (niebloid)
creates a max heap out of a range of elements
make_heap
(function template)
creates a max heap out of a range of elements
ranges::make_heap (C++20)
(niebloid)
turns a max heap into a range of elements sorted in ascending order
sort_heap
(function template)
turns a max heap into a range of elements sorted in ascending order
ranges::sort_heap (C++20)
(niebloid)
checks if the given range is a max heap
is_heap (C++11)
(function template)

[Link] 9/14
14/10/2024, 15:09 Algorithms library - [Link]
checks if the given range is a max heap
ranges::is_heap (C++20)
(niebloid)
finds the largest subrange that is a max heap
is_heap_until (C++11)
(function template)
finds the largest subrange that is a max heap
ranges::is_heap_until (C++20)
(niebloid)

Minimum/maximum operations

Defined in header <algorithm>


returns the greater of the given values
max
(function template)
returns the greater of the given values
ranges::max (C++20)
(niebloid)
returns the largest element in a range
max_element
(function template)
returns the largest element in a range
ranges::max_element (C++20)
(niebloid)
returns the smaller of the given values
min
(function template)
returns the smaller of the given values
ranges::min (C++20) (niebloid)
returns the smallest element in a range
min_element
(function template)
returns the smallest element in a range
ranges::min_element (C++20)
(niebloid)
returns the smaller and larger of two elements
minmax (C++11)
(function template)
returns the smaller and larger of two elements
ranges::minmax (C++20)
(niebloid)
returns the smallest and the largest elements in a range
minmax_element (C++11)
(function template)
returns the smallest and the largest elements in a range
ranges::minmax_element (C++20)
(niebloid)
clamps a value between a pair of boundary values
clamp (C++17)
(function template)
clamps a value between a pair of boundary values
ranges::clamp (C++20) (niebloid)

Lexicographical comparison operations

Defined in header <algorithm>


returns true if one range is lexicographically less than another
lexicographical_compare
(function template)

returns true if one range is lexicographically less than another


ranges::lexicographical_compare (C++20)
(niebloid)
compares two ranges using three-way comparison
lexicographical_compare_three_way (C++20)
(function template)

Permutation operations

Defined in header <algorithm>

[Link] 10/14
14/10/2024, 15:09 Algorithms library - [Link]
generates the next greater lexicographic permutation of a range of elements
next_permutation
(function template)
generates the next greater lexicographic permutation of a range of elements
ranges::next_permutation (C++20)
(niebloid)
generates the next smaller lexicographic permutation of a range of elements
prev_permutation
(function template)
generates the next smaller lexicographic permutation of a range of elements
ranges::prev_permutation (C++20)
(niebloid)
determines if a sequence is a permutation of another sequence
is_permutation (C++11)
(function template)
determines if a sequence is a permutation of another sequence
ranges::is_permutation (C++20) (niebloid)

Numeric operations
Defined in header <numeric>
fills a range with successive increments of the starting value
iota (C++11)
(function template)
fills a range with successive increments of the starting value
ranges::iota (C++23)
(niebloid)
sums up or folds a range of elements
accumulate
(function template)
computes the inner product of two ranges of elements
inner_product
(function template)
computes the differences between adjacent elements in a range
adjacent_difference
(function template)
computes the partial sum of a range of elements
partial_sum
(function template)
similar to std::accumulate, except out of order
reduce (C++17) (function template)

exclusive_scan (C++17) similar to std::partial_sum, excludes the ith input element from the ith sum
(function template)

inclusive_scan (C++17) similar to std::partial_sum, includes the ith input element in the ith sum
(function template)
applies an invocable, then reduces out of order
transform_reduce (C++17)
(function template)
applies an invocable, then calculates exclusive scan
transform_exclusive_scan (C++17)
(function template)
applies an invocable, then calculates inclusive scan
transform_inclusive_scan (C++17)
(function template)

Operations on uninitialized memory


Defined in header <memory>
copies a range of objects to an uninitialized area of
uninitialized_copy memory
(function template)
copies a range of objects to an uninitialized area of
ranges::uninitialized_copy (C++20) memory
(niebloid)

[Link] 11/14
14/10/2024, 15:09 Algorithms library - [Link]
copies a number of objects to an uninitialized area of
uninitialized_copy_n (C++11) memory
(function template)
copies a number of objects to an uninitialized area of
ranges::uninitialized_copy_n (C++20) memory
(niebloid)
copies an object to an uninitialized area of memory,
uninitialized_fill defined by a range
(function template)
copies an object to an uninitialized area of memory,
ranges::uninitialized_fill (C++20) defined by a range
(niebloid)
copies an object to an uninitialized area of memory,
uninitialized_fill_n defined by a start and a count
(function template)
copies an object to an uninitialized area of memory,
ranges::uninitialized_fill_n (C++20) defined by a start and a count
(niebloid)
moves a range of objects to an uninitialized area of
uninitialized_move (C++17) memory
(function template)
moves a range of objects to an uninitialized area of
ranges::uninitialized_move (C++20) memory
(niebloid)
moves a number of objects to an uninitialized area of
uninitialized_move_n (C++17) memory
(function template)
moves a number of objects to an uninitialized area of
ranges::uninitialized_move_n (C++20) memory
(niebloid)
constructs objects by default-initialization in an
uninitialized_default_construct (C++17) uninitialized area of memory, defined by a range
(function template)
constructs objects by default-initialization in an
ranges::uninitialized_default_construct (C++20) uninitialized area of memory, defined by a range
(niebloid)
constructs objects by default-initialization in an
uninitialized area of memory, defined by a start and a
uninitialized_default_construct_n (C++17)
count
(function template)
constructs objects by default-initialization in an
ranges::uninitialized_default_construct_n (C++20) uninitialized area of memory, defined by a start and count
(niebloid)
constructs objects by value-initialization in an uninitialized
uninitialized_value_construct (C++17) area of memory, defined by a range
(function template)
constructs objects by value-initialization in an uninitialized
ranges::uninitialized_value_construct (C++20) area of memory, defined by a range
(niebloid)
constructs objects by value-initialization in an uninitialized
uninitialized_value_construct_n (C++17) area of memory, defined by a start and a count
(function template)

ranges::uninitialized_value_construct_n (C++20) constructs objects by value-initialization in an uninitialized


area of memory, defined by a start and a count
[Link] 12/14
14/10/2024, 15:09 Algorithms library - [Link]
(niebloid)
destroys a range of objects
destroy (C++17)
(function template)
destroys a range of objects
ranges::destroy (C++20)
(niebloid)
destroys a number of objects in a range
destroy_n (C++17)
(function template)
destroys a number of objects in a range
ranges::destroy_n (C++20)
(niebloid)
destroys an object at a given address
destroy_at (C++17)
(function template)
destroys an object at a given address
ranges::destroy_at (C++20)
(niebloid)
creates an object at a given address
construct_at (C++20)
(function template)
creates an object at a given address
ranges::construct_at (C++20)
(niebloid)

Random number generation


Defined in header <random>
fills a range with random numbers from a uniform random bit generator
ranges::generate_random (C++26)
(niebloid)

Notes

Feature-test macro Value Std Feature


__cpp_lib_algorithm_iterator_requirements 202207L (C++23) Ranges iterators as inputs to non-Ranges algorithms
__cpp_lib_clamp 201603L (C++17) std::clamp
201806L (C++20) Constexpr for algorithms
__cpp_lib_constexpr_algorithms
202306L (C++26) Constexpr stable sorting
__cpp_lib_algorithm_default_value_type 202403L (C++26) List-initialization for algorithms
__cpp_lib_freestanding_algorithm 202311L (C++26) Freestanding facilities in <algorithm>
Making non-modifying sequence operations more robust (two-range overloads for std::mismatch,
__cpp_lib_robust_nonmodifying_seq_ops 201304L (C++14)
std::equal and std::is_permutation)
__cpp_lib_sample 201603L (C++17) std::sample
__cpp_lib_shift 201806L (C++20) std::shift_left and std::shift_right

C library
Defined in header <cstdlib>
sorts a range of elements with unspecified type
qsort
(function)
searches an array for an element of unspecified type
bsearch
(function)

[Link] 13/14
14/10/2024, 15:09 Algorithms library - [Link]

Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

DR Applied to Behavior as published Correct behavior


there can be elements
LWG 193 ([Link] C++98 heap required *first to be the largest element
equal to *first
LWG 2150 ([Link] C++98 the definition of a sorted sequence was incorrect corrected
the heap requirement did not match the
LWG 2166 ([Link] C++98 requirement improved
definition of max heap closely enough

See also

C documentation for Algorithms

Retrieved from "[Link]

[Link] 14/14

You might also like