Difference between revisions of "cpp/algorithm"
(Replaced content with "bla bla black sheep have you any wool no sir no sir .... PuTin took it toooo") |
(Undo revision 138584 by 61.2.194.101 (talk)) |
||
Line 1: | Line 1: | ||
− | + | {{title | Algorithms library}} | |
+ | {{cpp/algorithm/ranges/navbar}} | ||
− | + | 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 {{tt|[first, last)}} where {{tt|last}} refers to the element ''past'' the last element to inspect or modify. | |
− | + | {{rrev|since=c++20| | |
+ | ===== {{rl|ranges|Constrained algorithms}} ===== | ||
+ | C++20 provides [[cpp/language/constraints|constrained]] versions of most algorithms in the namespace {{tt|std::ranges}}. In these algorithms, a range can be specified as either an [[cpp/iterator/input_or_output_iterator|iterator]]-[[cpp/iterator/sentinel_for|sentinel]] pair or as a single {{lconcept|range}} argument, and projections and pointer-to-member callables are supported. Additionally, the [[cpp/algorithm/ranges#Return_types|return types]] of most algorithms have been changed to return all potentially useful information computed during the execution of the algorithm. | ||
+ | {{source|1= | ||
+ | std::vector<int> v = {7, 1, 4, 0, -1}; | ||
+ | std::ranges::sort(v); // constrained algorithm | ||
+ | }} | ||
+ | }} | ||
+ | |||
+ | |||
+ | {{rrev|since=c++17| | ||
+ | =====Execution policies===== | ||
+ | Most algorithms have overloads that accept execution policies. The standard library algorithms support several [[cpp/algorithm/execution_policy_tag_t|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 [[cpp/algorithm/execution_policy_tag|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 {{lc|std::for_each}} and {{lc|std::for_each_n}}) are allowed to make arbitrary copies of elements from ranges, as long as both {{c|std::is_trivially_copy_constructible_v<T>}} and {{c|std::is_trivially_destructible_v<T>}} are {{c|true}}, where {{tt|T}} is the type of elements. | ||
+ | |||
+ | {{dsc begin}} | ||
+ | {{dsc header | execution }} | ||
+ | {{dsc namespace | std::execution }} | ||
+ | {{dsc inc | cpp/algorithm/dsc execution_policy_tag_t }} | ||
+ | {{dsc inc | cpp/algorithm/dsc execution_policy_tag }} | ||
+ | {{dsc namespace | std }} | ||
+ | {{dsc inc | cpp/algorithm/dsc is_execution_policy }} | ||
+ | {{dsc end}} | ||
+ | |||
+ | |||
+ | {{feature test macro|__cpp_lib_parallel_algorithm}} (for parallel version of algorithms). | ||
+ | |||
+ | {{feature test macro|__cpp_lib_execution}} (for execution policies). | ||
+ | }} | ||
+ | |||
+ | {{dsc begin}} | ||
+ | {{dsc h2 | Non-modifying sequence operations}} | ||
+ | {{dsc header | algorithm}} | ||
+ | {{dsc inc | cpp/algorithm/dsc all_any_none_of}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc all_any_none_of}} | ||
+ | {{dsc inc | cpp/algorithm/dsc for_each}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc for_each}} | ||
+ | {{dsc inc | cpp/algorithm/dsc for_each_n}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc for_each_n}} | ||
+ | {{dsc inc | cpp/algorithm/dsc count}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc count}} | ||
+ | {{dsc inc | cpp/algorithm/dsc mismatch}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc mismatch}} | ||
+ | {{dsc inc | cpp/algorithm/dsc find}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc find}} | ||
+ | {{dsc inc | cpp/algorithm/dsc find_end}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc find_end}} | ||
+ | {{dsc inc | cpp/algorithm/dsc find_first_of}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc find_first_of}} | ||
+ | {{dsc inc | cpp/algorithm/dsc adjacent_find}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc adjacent_find}} | ||
+ | {{dsc inc | cpp/algorithm/dsc search}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc search}} | ||
+ | {{dsc inc | cpp/algorithm/dsc search_n}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc search_n}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc starts_with}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc ends_with}} | ||
+ | |||
+ | {{dsc h2 | Modifying sequence operations}} | ||
+ | {{dsc header | algorithm}} | ||
+ | {{dsc inc | cpp/algorithm/dsc copy}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc copy}} | ||
+ | {{dsc inc | cpp/algorithm/dsc copy_n}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc copy_n}} | ||
+ | {{dsc inc | cpp/algorithm/dsc copy_backward}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc copy_backward}} | ||
+ | {{dsc inc | cpp/algorithm/dsc move}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc move}} | ||
+ | {{dsc inc | cpp/algorithm/dsc move_backward}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc move_backward}} | ||
+ | {{dsc inc | cpp/algorithm/dsc fill}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc fill}} | ||
+ | {{dsc inc | cpp/algorithm/dsc fill_n}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc fill_n}} | ||
+ | {{dsc inc | cpp/algorithm/dsc transform}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc transform}} | ||
+ | {{dsc inc | cpp/algorithm/dsc generate}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc generate}} | ||
+ | {{dsc inc | cpp/algorithm/dsc generate_n}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc generate_n}} | ||
+ | {{dsc inc | cpp/algorithm/dsc remove}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc remove}} | ||
+ | {{dsc inc | cpp/algorithm/dsc remove_copy}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc remove_copy}} | ||
+ | {{dsc inc | cpp/algorithm/dsc replace}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc replace}} | ||
+ | {{dsc inc | cpp/algorithm/dsc replace_copy}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc replace_copy}} | ||
+ | {{dsc inc | cpp/algorithm/dsc swap}} | ||
+ | {{dsc inc | cpp/algorithm/dsc swap_ranges}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc swap_ranges}} | ||
+ | {{dsc inc | cpp/algorithm/dsc iter_swap}} | ||
+ | {{dsc inc | cpp/algorithm/dsc reverse}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc reverse}} | ||
+ | {{dsc inc | cpp/algorithm/dsc reverse_copy}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc reverse_copy}} | ||
+ | {{dsc inc | cpp/algorithm/dsc rotate}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc rotate}} | ||
+ | {{dsc inc | cpp/algorithm/dsc rotate_copy}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc rotate_copy}} | ||
+ | {{dsc inc | cpp/algorithm/dsc shift}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc shift}} | ||
+ | {{dsc inc | cpp/algorithm/dsc random_shuffle}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc shuffle}} | ||
+ | {{dsc inc | cpp/algorithm/dsc sample}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc sample}} | ||
+ | {{dsc inc | cpp/algorithm/dsc unique}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc unique}} | ||
+ | {{dsc inc | cpp/algorithm/dsc unique_copy}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc unique_copy}} | ||
+ | |||
+ | {{dsc h2 | Partitioning operations}} | ||
+ | {{dsc header | algorithm}} | ||
+ | {{dsc inc | cpp/algorithm/dsc is_partitioned}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc is_partitioned}} | ||
+ | {{dsc inc | cpp/algorithm/dsc partition}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc partition}} | ||
+ | {{dsc inc | cpp/algorithm/dsc partition_copy}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc partition_copy}} | ||
+ | {{dsc inc | cpp/algorithm/dsc stable_partition}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc stable_partition}} | ||
+ | {{dsc inc | cpp/algorithm/dsc partition_point}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc partition_point}} | ||
+ | |||
+ | {{dsc h2 | Sorting operations}} | ||
+ | {{dsc header | algorithm}} | ||
+ | {{dsc inc | cpp/algorithm/dsc is_sorted}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc is_sorted}} | ||
+ | {{dsc inc | cpp/algorithm/dsc is_sorted_until}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc is_sorted_until}} | ||
+ | {{dsc inc | cpp/algorithm/dsc sort}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc sort}} | ||
+ | {{dsc inc | cpp/algorithm/dsc partial_sort}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc partial_sort}} | ||
+ | {{dsc inc | cpp/algorithm/dsc partial_sort_copy}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc partial_sort_copy}} | ||
+ | {{dsc inc | cpp/algorithm/dsc stable_sort}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc stable_sort}} | ||
+ | {{dsc inc | cpp/algorithm/dsc nth_element}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc nth_element}} | ||
+ | |||
+ | {{dsc h2 | Binary search operations (on sorted ranges)}} | ||
+ | {{dsc header | algorithm}} | ||
+ | {{dsc inc | cpp/algorithm/dsc lower_bound}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc lower_bound}} | ||
+ | {{dsc inc | cpp/algorithm/dsc upper_bound}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc upper_bound}} | ||
+ | {{dsc inc | cpp/algorithm/dsc binary_search}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc binary_search}} | ||
+ | {{dsc inc | cpp/algorithm/dsc equal_range}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc equal_range}} | ||
+ | |||
+ | {{dsc h2 | Other operations on sorted ranges}} | ||
+ | {{dsc header | algorithm}} | ||
+ | {{dsc inc | cpp/algorithm/dsc merge}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc merge}} | ||
+ | {{dsc inc | cpp/algorithm/dsc inplace_merge}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc inplace_merge}} | ||
+ | |||
+ | {{dsc h2 | Set operations (on sorted ranges)}} | ||
+ | {{dsc header | algorithm}} | ||
+ | {{dsc inc | cpp/algorithm/dsc includes}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc includes}} | ||
+ | {{dsc inc | cpp/algorithm/dsc set_difference}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc set_difference}} | ||
+ | {{dsc inc | cpp/algorithm/dsc set_intersection}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc set_intersection}} | ||
+ | {{dsc inc | cpp/algorithm/dsc set_symmetric_difference}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc set_symmetric_difference}} | ||
+ | {{dsc inc | cpp/algorithm/dsc set_union}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc set_union}} | ||
+ | |||
+ | {{dsc h2 | Heap operations}} | ||
+ | {{dsc header | algorithm}} | ||
+ | {{dsc inc | cpp/algorithm/dsc is_heap}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc is_heap}} | ||
+ | {{dsc inc | cpp/algorithm/dsc is_heap_until}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc is_heap_until}} | ||
+ | {{dsc inc | cpp/algorithm/dsc make_heap}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc make_heap}} | ||
+ | {{dsc inc | cpp/algorithm/dsc push_heap}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc push_heap}} | ||
+ | {{dsc inc | cpp/algorithm/dsc pop_heap}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc pop_heap}} | ||
+ | {{dsc inc | cpp/algorithm/dsc sort_heap}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc sort_heap}} | ||
+ | |||
+ | {{dsc h2 | Minimum/maximum operations}} | ||
+ | {{dsc header | algorithm}} | ||
+ | {{dsc inc | cpp/algorithm/dsc max}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc max}} | ||
+ | {{dsc inc | cpp/algorithm/dsc max_element}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc max_element}} | ||
+ | {{dsc inc | cpp/algorithm/dsc min}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc min}} | ||
+ | {{dsc inc | cpp/algorithm/dsc min_element}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc min_element}} | ||
+ | {{dsc inc | cpp/algorithm/dsc minmax}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc minmax}} | ||
+ | {{dsc inc | cpp/algorithm/dsc minmax_element}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc minmax_element}} | ||
+ | {{dsc inc | cpp/algorithm/dsc clamp}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc clamp}} | ||
+ | |||
+ | {{dsc h2 | Comparison operations}} | ||
+ | {{dsc header | algorithm}} | ||
+ | {{dsc inc | cpp/algorithm/dsc equal}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc equal}} | ||
+ | {{dsc inc | cpp/algorithm/dsc lexicographical_compare}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc lexicographical_compare}} | ||
+ | {{dsc inc | cpp/algorithm/dsc lexicographical_compare_three_way}} | ||
+ | |||
+ | {{dsc h2 | Permutation operations}} | ||
+ | {{dsc header | algorithm}} | ||
+ | {{dsc inc | cpp/algorithm/dsc is_permutation}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc is_permutation}} | ||
+ | {{dsc inc | cpp/algorithm/dsc next_permutation}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc next_permutation}} | ||
+ | {{dsc inc | cpp/algorithm/dsc prev_permutation}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc prev_permutation}} | ||
+ | |||
+ | {{dsc h2 | Numeric operations}} | ||
+ | {{dsc header | numeric}} | ||
+ | {{dsc inc | cpp/algorithm/dsc iota}} | ||
+ | {{dsc inc | cpp/algorithm/ranges/dsc iota}} | ||
+ | {{dsc inc | cpp/algorithm/dsc accumulate}} | ||
+ | {{dsc inc | cpp/algorithm/dsc inner_product}} | ||
+ | {{dsc inc | cpp/algorithm/dsc adjacent_difference}} | ||
+ | {{dsc inc | cpp/algorithm/dsc partial_sum}} | ||
+ | {{dsc inc | cpp/algorithm/dsc reduce}} | ||
+ | {{dsc inc | cpp/algorithm/dsc exclusive_scan}} | ||
+ | {{dsc inc | cpp/algorithm/dsc inclusive_scan}} | ||
+ | {{dsc inc | cpp/algorithm/dsc transform_reduce}} | ||
+ | {{dsc inc | cpp/algorithm/dsc transform_exclusive_scan}} | ||
+ | {{dsc inc | cpp/algorithm/dsc transform_inclusive_scan}} | ||
+ | |||
+ | {{dsc h2 | Operations on uninitialized memory}} | ||
+ | |||
+ | {{dsc begin}} | ||
+ | {{dsc header | memory}} | ||
+ | {{dsc inc | cpp/memory/dsc uninitialized_copy}} | ||
+ | {{dsc inc | cpp/memory/ranges/dsc uninitialized_copy}} | ||
+ | {{dsc inc | cpp/memory/dsc uninitialized_copy_n}} | ||
+ | {{dsc inc | cpp/memory/ranges/dsc uninitialized_copy_n}} | ||
+ | {{dsc inc | cpp/memory/dsc uninitialized_fill}} | ||
+ | {{dsc inc | cpp/memory/ranges/dsc uninitialized_fill}} | ||
+ | {{dsc inc | cpp/memory/dsc uninitialized_fill_n}} | ||
+ | {{dsc inc | cpp/memory/ranges/dsc uninitialized_fill_n}} | ||
+ | {{dsc inc | cpp/memory/dsc uninitialized_move}} | ||
+ | {{dsc inc | cpp/memory/ranges/dsc uninitialized_move}} | ||
+ | {{dsc inc | cpp/memory/dsc uninitialized_move_n}} | ||
+ | {{dsc inc | cpp/memory/ranges/dsc uninitialized_move_n}} | ||
+ | {{dsc inc | cpp/memory/dsc uninitialized_default_construct}} | ||
+ | {{dsc inc | cpp/memory/ranges/dsc uninitialized_default_construct}} | ||
+ | {{dsc inc | cpp/memory/dsc uninitialized_default_construct_n}} | ||
+ | {{dsc inc | cpp/memory/ranges/dsc uninitialized_default_construct_n}} | ||
+ | {{dsc inc | cpp/memory/dsc uninitialized_value_construct}} | ||
+ | {{dsc inc | cpp/memory/ranges/dsc uninitialized_value_construct}} | ||
+ | {{dsc inc | cpp/memory/dsc uninitialized_value_construct_n}} | ||
+ | {{dsc inc | cpp/memory/ranges/dsc uninitialized_value_construct_n}} | ||
+ | {{dsc inc | cpp/memory/dsc destroy}} | ||
+ | {{dsc inc | cpp/memory/ranges/dsc destroy}} | ||
+ | {{dsc inc | cpp/memory/dsc destroy_n}} | ||
+ | {{dsc inc | cpp/memory/ranges/dsc destroy_n}} | ||
+ | {{dsc inc | cpp/memory/dsc destroy_at}} | ||
+ | {{dsc inc | cpp/memory/ranges/dsc destroy_at}} | ||
+ | {{dsc inc | cpp/memory/dsc construct_at}} | ||
+ | {{dsc inc | cpp/memory/ranges/dsc construct_at}} | ||
+ | |||
+ | {{dsc h2 | C library}} | ||
+ | {{dsc header | cstdlib}} | ||
+ | {{dsc inc | cpp/algorithm/dsc qsort}} | ||
+ | {{dsc inc | cpp/algorithm/dsc bsearch}} | ||
+ | {{dsc end}} | ||
+ | |||
+ | ===See also=== | ||
+ | {{dsc begin}} | ||
+ | {{dsc see c | c/algorithm | Algorithms | nomono=true}} | ||
+ | {{dsc end}} | ||
+ | |||
+ | {{langlinks|ar|de|es|fr|it|ja|pt|ru|tr|zh}} |
Revision as of 12:25, 11 March 2022
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.
Execution policiesMost 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
|
(since C++17) |
Non-modifying sequence operations | |
Defined in header
<algorithm> | |
(C++11)(C++11)(C++11) |
checks if a predicate is true for all, any or none of the elements in a range (function template) |
(C++20)(C++20)(C++20) |
checks if a predicate is true for all, any or none of the elements in a range (niebloid) |
applies a function to a range of elements (function template) | |
(C++20) |
applies a function to a range of elements (niebloid) |
(C++17) |
applies a function object to the first N elements of a sequence (function template) |
(C++20) |
applies a function object to the first N elements of a sequence (niebloid) |
returns the number of elements satisfying specific criteria (function template) | |
(C++20)(C++20) |
returns the number of elements satisfying specific criteria (niebloid) |
finds the first position where two ranges differ (function template) | |
(C++20) |
finds the first position where two ranges differ (niebloid) |
(C++11) |
finds the first element satisfying specific criteria (function template) |
(C++20)(C++20)(C++20) |
finds the first element satisfying specific criteria (niebloid) |
finds the last sequence of elements in a certain range (function template) | |
(C++20) |
finds the last sequence of elements in a certain range (niebloid) |
searches for any one of a set of elements (function template) | |
(C++20) |
searches for any one of a set of elements (niebloid) |
finds the first two adjacent items that are equal (or satisfy a given predicate) (function template) | |
(C++20) |
finds the first two adjacent items that are equal (or satisfy a given predicate) (niebloid) |
searches for the first occurrence of a range of elements (function template) | |
(C++20) |
searches for the first occurrence of a range of elements (niebloid) |
searches for the first occurrence of a number consecutive copies of an element in a range (function template) | |
(C++20) |
searches for the first occurrence of a number consecutive copies of an element in a range (niebloid) |
(C++23) |
checks whether a range starts with another range (niebloid) |
(C++23) |
checks whether a range ends with another range (niebloid) |
Modifying sequence operations | |
Defined in header
<algorithm> | |
(C++11) |
copies a range of elements to a new location (function template) |
(C++20)(C++20) |
copies a range of elements to a new location (niebloid) |
(C++11) |
copies a number of elements to a new location (function template) |
(C++20) |
copies a number of elements to a new location (niebloid) |
copies a range of elements in backwards order (function template) | |
(C++20) |
copies a range of elements in backwards order (niebloid) |
(C++11) |
moves a range of elements to a new location (function template) |
(C++20) |
moves a range of elements to a new location (niebloid) |
(C++11) |
moves a range of elements to a new location in backwards order (function template) |
(C++20) |
moves a range of elements to a new location in backwards order (niebloid) |
copy-assigns the given value to every element in a range (function template) | |
(C++20) |
assigns a range of elements a certain value (niebloid) |
copy-assigns the given value to N elements in a range (function template) | |
(C++20) |
assigns a value to a number of elements (niebloid) |
applies a function to a range of elements, storing results in a destination range (function template) | |
(C++20) |
applies a function to a range of elements (niebloid) |
assigns the results of successive function calls to every element in a range (function template) | |
(C++20) |
saves the result of a function in a range (niebloid) |
assigns the results of successive function calls to N elements in a range (function template) | |
(C++20) |
saves the result of N applications of a function (niebloid) |
removes elements satisfying specific criteria (function template) | |
(C++20)(C++20) |
removes elements satisfying specific criteria (niebloid) |
copies a range of elements omitting those that satisfy specific criteria (function template) | |
(C++20)(C++20) |
copies a range of elements omitting those that satisfy specific criteria (niebloid) |
replaces all values satisfying specific criteria with another value (function template) | |
(C++20)(C++20) |
replaces all values satisfying specific criteria with another value (niebloid) |
copies a range, replacing elements satisfying specific criteria with another value (function template) | |
(C++20)(C++20) |
copies a range, replacing elements satisfying specific criteria with another value (niebloid) |
swaps the values of two objects (function template) | |
swaps two ranges of elements (function template) | |
(C++20) |
swaps two ranges of elements (niebloid) |
swaps the elements pointed to by two iterators (function template) | |
reverses the order of elements in a range (function template) | |
(C++20) |
reverses the order of elements in a range (niebloid) |
creates a copy of a range that is reversed (function template) | |
(C++20) |
creates a copy of a range that is reversed (niebloid) |
rotates the order of elements in a range (function template) | |
(C++20) |
rotates the order of elements in a range (niebloid) |
copies and rotate a range of elements (function template) | |
(C++20) |
copies and rotate a range of elements (niebloid) |
(C++20) |
shifts elements in a range (function template) |
shifts elements in a range (niebloid) | |
(until C++17)(C++11) |
randomly re-orders elements in a range (function template) |
(C++20) |
randomly re-orders elements in a range (niebloid) |
(C++17) |
selects N random elements from a sequence (function template) |
(C++20) |
selects N random elements from a sequence (niebloid) |
removes consecutive duplicate elements in a range (function template) | |
(C++20) |
removes consecutive duplicate elements in a range (niebloid) |
creates a copy of some range of elements that contains no consecutive duplicates (function template) | |
(C++20) |
creates a copy of some range of elements that contains no consecutive duplicates (niebloid) |
Partitioning operations | |
Defined in header
<algorithm> | |
(C++11) |
determines if the range is partitioned by the given predicate (function template) |
(C++20) |
determines if the range is partitioned by the given predicate (niebloid) |
divides a range of elements into two groups (function template) | |
(C++20) |
divides a range of elements into two groups (niebloid) |
(C++11) |
copies a range dividing the elements into two groups (function template) |
(C++20) |
copies a range dividing the elements into two groups (niebloid) |
divides elements into two groups while preserving their relative order (function template) | |
(C++20) |
divides elements into two groups while preserving their relative order (niebloid) |
(C++11) |
locates the partition point of a partitioned range (function template) |
(C++20) |
locates the partition point of a partitioned range (niebloid) |
Sorting operations | |
Defined in header
<algorithm> | |
(C++11) |
checks whether a range is sorted into ascending order (function template) |
(C++20) |
checks whether a range is sorted into ascending order (niebloid) |
(C++11) |
finds the largest sorted subrange (function template) |
(C++20) |
finds the largest sorted subrange (niebloid) |
sorts a range into ascending order (function template) | |
(C++20) |
sorts a range into ascending order (niebloid) |
sorts the first N elements of a range (function template) | |
(C++20) |
sorts the first N elements of a range (niebloid) |
copies and partially sorts a range of elements (function template) | |
(C++20) |
copies and partially sorts a range of elements (niebloid) |
sorts a range of elements while preserving order between equal elements (function template) | |
(C++20) |
sorts a range of elements while preserving order between equal elements (niebloid) |
partially sorts the given range making sure that it is partitioned by the given element (function template) | |
(C++20) |
partially sorts the given range making sure that it is partitioned by the given element (niebloid) |
Binary search operations (on sorted ranges) | |
Defined in header
<algorithm> | |
returns an iterator to the first element not less than the given value (function template) | |
(C++20) |
returns an iterator to the first element not less than the given value (niebloid) |
returns an iterator to the first element greater than a certain value (function template) | |
(C++20) |
returns an iterator to the first element greater than a certain value (niebloid) |
determines if an element exists in a partially-ordered range (function template) | |
(C++20) |
determines if an element exists in a partially-ordered range (niebloid) |
returns range of elements matching a specific key (function template) | |
(C++20) |
returns range of elements matching a specific key (niebloid) |
Other operations on sorted ranges | |
Defined in header
<algorithm> | |
merges two sorted ranges (function template) | |
(C++20) |
merges two sorted ranges (niebloid) |
merges two ordered ranges in-place (function template) | |
(C++20) |
merges two ordered ranges in-place (niebloid) |
Set operations (on sorted ranges) | |
Defined in header
<algorithm> | |
returns true if one sequence is a subsequence of another (function template) | |
(C++20) |
returns true if one sequence is a subsequence of another (niebloid) |
computes the difference between two sets (function template) | |
(C++20) |
computes the difference between two sets (niebloid) |
computes the intersection of two sets (function template) | |
(C++20) |
computes the intersection of two sets (niebloid) |
computes the symmetric difference between two sets (function template) | |
computes the symmetric difference between two sets (niebloid) | |
computes the union of two sets (function template) | |
(C++20) |
computes the union of two sets (niebloid) |
Heap operations | |
Defined in header
<algorithm> | |
(C++11) |
checks if the given range is a max heap (function template) |
(C++20) |
checks if the given range is a max heap (niebloid) |
(C++11) |
finds the largest subrange that is a max heap (function template) |
(C++20) |
finds the largest subrange that is a max heap (niebloid) |
creates a max heap out of a range of elements (function template) | |
(C++20) |
creates a max heap out of a range of elements (niebloid) |
adds an element to a max heap (function template) | |
(C++20) |
adds an element to a max heap (niebloid) |
removes the largest element from a max heap (function template) | |
(C++20) |
removes the largest element from a max heap (niebloid) |
turns a max heap into a range of elements sorted in ascending order (function template) | |
(C++20) |
turns a max heap into a range of elements sorted in ascending order (niebloid) |
Minimum/maximum operations | |
Defined in header
<algorithm> | |
returns the greater of the given values (function template) | |
(C++20) |
returns the greater of the given values (niebloid) |
returns the largest element in a range (function template) | |
(C++20) |
returns the largest element in a range (niebloid) |
returns the smaller of the given values (function template) | |
(C++20) |
returns the smaller of the given values (niebloid) |
returns the smallest element in a range (function template) | |
(C++20) |
returns the smallest element in a range (niebloid) |
(C++11) |
returns the smaller and larger of two elements (function template) |
(C++20) |
returns the smaller and larger of two elements (niebloid) |
(C++11) |
returns the smallest and the largest elements in a range (function template) |
(C++20) |
returns the smallest and the largest elements in a range (niebloid) |
(C++17) |
clamps a value between a pair of boundary values (function template) |
(C++20) |
clamps a value between a pair of boundary values (niebloid) |
Comparison operations | |
Defined in header
<algorithm> | |
determines if two sets of elements are the same (function template) | |
(C++20) |
determines if two sets of elements are the same (niebloid) |
returns true if one range is lexicographically less than another (function template) | |
returns true if one range is lexicographically less than another (niebloid) | |
compares two ranges using three-way comparison (function template) | |
Permutation operations | |
Defined in header
<algorithm> | |
(C++11) |
determines if a sequence is a permutation of another sequence (function template) |
(C++20) |
determines if a sequence is a permutation of another sequence (niebloid) |
generates the next greater lexicographic permutation of a range of elements (function template) | |
(C++20) |
generates the next greater lexicographic permutation of a range of elements (niebloid) |
generates the next smaller lexicographic permutation of a range of elements (function template) | |
(C++20) |
generates the next smaller lexicographic permutation of a range of elements (niebloid) |
Numeric operations | |
Defined in header
<numeric> | |
(C++11) |
fills a range with successive increments of the starting value (function template) |
(C++23) |
fills a range with successive increments of the starting value (niebloid) |
sums up or folds a range of elements (function template) | |
computes the inner product of two ranges of elements (function template) | |
computes the differences between adjacent elements in a range (function template) | |
computes the partial sum of a range of elements (function template) | |
(C++17) |
similar to std::accumulate, except out of order (function template) |
(C++17) |
similar to std::partial_sum, excludes the ith input element from the ith sum (function template) |
(C++17) |
similar to std::partial_sum, includes the ith input element in the ith sum (function template) |
(C++17) |
applies an invocable, then reduces out of order (function template) |
(C++17) |
applies an invocable, then calculates exclusive scan (function template) |
(C++17) |
applies an invocable, then calculates inclusive scan (function template) |
Operations on uninitialized memory |
Defined in header
<memory> | |
copies a range of objects to an uninitialized area of memory (function template) | |
(C++20) |
copies a range of objects to an uninitialized area of memory (niebloid) |
(C++11) |
copies a number of objects to an uninitialized area of memory (function template) |
(C++20) |
copies a number of objects to an uninitialized area of memory (niebloid) |
copies an object to an uninitialized area of memory, defined by a range (function template) | |
(C++20) |
copies an object to an uninitialized area of memory, defined by a range (niebloid) |
copies an object to an uninitialized area of memory, defined by a start and a count (function template) | |
(C++20) |
copies an object to an uninitialized area of memory, defined by a start and a count (niebloid) |
(C++17) |
moves a range of objects to an uninitialized area of memory (function template) |
(C++20) |
moves a range of objects to an uninitialized area of memory (niebloid) |
(C++17) |
moves a number of objects to an uninitialized area of memory (function template) |
(C++20) |
moves a number of objects to an uninitialized area of memory (niebloid) |
constructs objects by default-initialization in an uninitialized area of memory, defined by a range (function template) | |
constructs objects by default-initialization in an 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 count (function template) | |
constructs objects by default-initialization in an uninitialized area of memory, defined by a start and count (niebloid) | |
constructs objects by value-initialization in an uninitialized area of memory, defined by a range (function template) | |
constructs objects by value-initialization in an uninitialized area of memory, defined by a range (niebloid) | |
constructs objects by value-initialization in an uninitialized area of memory, defined by a start and a count (function template) | |
constructs objects by value-initialization in an uninitialized area of memory, defined by a start and a count (niebloid) | |
(C++17) |
destroys a range of objects (function template) |
(C++20) |
destroys a range of objects (niebloid) |
(C++17) |
destroys a number of objects in a range (function template) |
(C++20) |
destroys a number of objects in a range (niebloid) |
(C++17) |
destroys an object at a given address (function template) |
(C++20) |
destroys an object at a given address (niebloid) |
(C++20) |
creates an object at a given address (function template) |
(C++20) |
creates an object at a given address (niebloid) |
C library | |
Defined in header
<cstdlib> | |
sorts a range of elements with unspecified type (function) | |
searches an array for an element of unspecified type (function) |
See also
C documentation for Algorithms
|