Skip to content

Commit 22e75d5

Browse files
committed
algorithm cstdlib
1 parent 001dc26 commit 22e75d5

3 files changed

Lines changed: 72 additions & 25 deletions

File tree

docs/standard-library/algorithm-functions.md

Lines changed: 55 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,43 @@ title: "<algorithm> functions | Microsoft Docs"
33
ms.custom: ""
44
ms.date: "11/04/2016"
55
ms.topic: "reference"
6-
f1_keywords: ["algorithm/std::adjacent_find", "algorithm/std::all_of", "algorithm/std::any_of", "algorithm/std::binary_search", "algorithm/std::copy", "algorithm/std::copy_backward", "algorithm/std::copy_if", "algorithm/std::copy_n", "algorithm/std::equal", "algorithm/std::equal_range", "algorithm/std::fill", "algorithm/std::fill_n", "algorithm/std::find", "algorithm/std::find_end", "algorithm/std::find_first_of", "algorithm/std::find_if", "algorithm/std::find_if_not", "algorithm/std::for_each", "algorithm/std::generate", "algorithm/std::generate_n", "algorithm/std::includes", "algorithm/std::inplace_merge", "algorithm/std::is_heap", "algorithm/std::is_heap_until", "algorithm/std::is_partitioned", "algorithm/std::is_permutation", "algorithm/std::is_sorted", "algorithm/std::is_sorted_until", "algorithm/std::iter_swap", "algorithm/std::lexicographical_compare", "algorithm/std::lower_bound", "algorithm/std::make_heap", "algorithm/std::max", "algorithm/std::max_element", "algorithm/std::merge", "algorithm/std::min", "algorithm/std::minmax", "algorithm/std::minmax_element", "algorithm/std::min_element", "algorithm/std::mismatch", "algorithm/std::move", "algorithm/std::move_backward", "algorithm/std::next_permutation", "algorithm/std::none_of", "algorithm/std::nth_element", "algorithm/std::partial_sort", "algorithm/std::partial_sort_copy", "algorithm/std::partition", "algorithm/std::partition_point", "algorithm/std::pop_heap", "algorithm/std::prev_permutation", "algorithm/std::push_heap", "algorithm/std::random_shuffle", "algorithm/std::remove", "algorithm/std::remove_copy", "algorithm/std::remove_copy_if", "algorithm/std::remove_if", "algorithm/std::replace", "algorithm/std::replace_copy", "algorithm/std::replace_copy_if", "algorithm/std::replace_if", "algorithm/std::reverse", "algorithm/std::reverse_copy", "algorithm/std::rotate", "algorithm/std::rotate_copy", "algorithm/std::search", "algorithm/std::search_n", "algorithm/std::set_difference", "algorithm/std::set_intersection", "algorithm/std::set_symmetric_difference", "algorithm/std::set_union", "algorithm/std::shuffle", "algorithm/std::sort", "algorithm/std::sort_heap", "algorithm/std::stable_partition", "algorithm/std::stable_sort", "algorithm/std::swap_ranges", "algorithm/std::transform", "algorithm/std::unique", "algorithm/std::unique_copy", "algorithm/std::upper_bound", "xutility/std::copy", "xutility/std::copy_backward", "xutility/std::copy_n", "xutility/std::count", "xutility/std::equal", "xutility/std::fill", "xutility/std::fill_n", "xutility/std::find", "xutility/std::is_permutation", "xutility/std::lexicographical_compare", "xutility/std::move", "xutility/std::move_backward", "xutility/std::reverse", "xutility/std::rotate", "algorithm/std::count_if", "algorithm/std::partition_copy", "algorithm/std::swap"]
6+
f1_keywords: ["algorithm/std::adjacent_find", "algorithm/std::all_of", "algorithm/std::any_of", "algorithm/std::binary_search", "algorithm/std::clamp", "algorithm/std::copy", "algorithm/std::copy_backward", "algorithm/std::copy_if", "algorithm/std::copy_n", "algorithm/std::equal", "algorithm/std::equal_range", "algorithm/std::fill", "algorithm/std::fill_n", "algorithm/std::find", "algorithm/std::find_end", "algorithm/std::find_first_of", "algorithm/std::find_if", "algorithm/std::find_if_not", "algorithm/std::for_each", "algorithm/std::generate", "algorithm/std::for_each_n", "algorithm/std::generate_n", "algorithm/std::includes", "algorithm/std::inplace_merge", "algorithm/std::is_heap", "algorithm/std::is_heap_until", "algorithm/std::is_partitioned", "algorithm/std::is_permutation", "algorithm/std::is_sorted", "algorithm/std::is_sorted_until", "algorithm/std::iter_swap", "algorithm/std::lexicographical_compare", "algorithm/std::lower_bound", "algorithm/std::make_heap", "algorithm/std::max", "algorithm/std::max_element", "algorithm/std::merge", "algorithm/std::min", "algorithm/std::minmax", "algorithm/std::minmax_element", "algorithm/std::min_element", "algorithm/std::mismatch", "algorithm/std::move", "algorithm/std::move_backward", "algorithm/std::next_permutation", "algorithm/std::none_of", "algorithm/std::nth_element", "algorithm/std::partial_sort", "algorithm/std::partial_sort_copy", "algorithm/std::partition", "algorithm/std::partition_point", "algorithm/std::pop_heap", "algorithm/std::prev_permutation", "algorithm/std::push_heap", "algorithm/std::random_shuffle", "algorithm/std::remove", "algorithm/std::remove_copy", "algorithm/std::remove_copy_if", "algorithm/std::remove_if", "algorithm/std::replace", "algorithm/std::replace_copy", "algorithm/std::replace_copy_if", "algorithm/std::replace_if", "algorithm/std::reverse", "algorithm/std::reverse_copy", "algorithm/std::rotate", "algorithm/std::rotate_copy", "algorithm/std::sample", "algorithm/std::search", "algorithm/std::search_n", "algorithm/std::set_difference", "algorithm/std::set_intersection", "algorithm/std::set_symmetric_difference", "algorithm/std::set_union", "algorithm/std::shuffle", "algorithm/std::sort", "algorithm/std::sort_heap", "algorithm/std::stable_partition", "algorithm/std::stable_sort", "algorithm/std::swap_ranges", "algorithm/std::transform", "algorithm/std::unique", "algorithm/std::unique_copy", "algorithm/std::upper_bound", "xutility/std::copy", "xutility/std::copy_backward", "xutility/std::copy_n", "xutility/std::count", "xutility/std::equal", "xutility/std::fill", "xutility/std::fill_n", "xutility/std::find", "xutility/std::is_permutation", "xutility/std::lexicographical_compare", "xutility/std::move", "xutility/std::move_backward", "xutility/std::reverse", "xutility/std::rotate", "algorithm/std::count_if", "algorithm/std::partition_copy", "algorithm/std::swap"]
77
dev_langs: ["C++"]
88
ms.assetid: c10b0c65-410c-4c83-abf8-8b7f61bba8d0
99
author: "corob-msft"
1010
ms.author: "corob"
11-
helpviewer_keywords: ["std::adjacent_find [C++]", "std::all_of [C++]", "std::any_of [C++]", "std::binary_search [C++]", "std::copy [C++]", "std::copy_backward [C++]", "std::copy_if [C++]", "std::copy_n [C++]", "std::equal [C++]", "std::equal_range [C++]", "std::fill [C++]", "std::fill_n [C++]", "std::find [C++]", "std::find_end [C++]", "std::find_first_of [C++]", "std::find_if [C++]", "std::find_if_not [C++]", "std::for_each [C++]", "std::generate [C++]", "std::generate_n [C++]", "std::includes [C++]", "std::inplace_merge [C++]", "std::is_heap [C++]", "std::is_heap_until [C++]", "std::is_partitioned [C++]", "std::is_permutation [C++]", "std::is_sorted [C++]", "std::is_sorted_until [C++]", "std::iter_swap [C++]", "std::lexicographical_compare [C++]", "std::lower_bound [C++]", "std::make_heap [C++]", "std::max [C++]", "std::max_element [C++]", "std::merge [C++]", "std::min [C++]", "std::minmax [C++]", "std::minmax_element [C++]", "std::min_element [C++]", "std::mismatch [C++]", "std::move [C++]", "std::move_backward [C++]", "std::next_permutation [C++]", "std::none_of [C++]", "std::nth_element [C++]", "std::partial_sort [C++]", "std::partial_sort_copy [C++]", "std::partition [C++]", "std::partition_point [C++]", "std::pop_heap [C++]", "std::prev_permutation [C++]", "std::push_heap [C++]", "std::random_shuffle [C++]", "std::remove [C++]", "std::remove_copy [C++]", "std::remove_copy_if [C++]", "std::remove_if [C++]", "std::replace [C++]", "std::replace_copy [C++]", "std::replace_copy_if [C++]", "std::replace_if [C++]", "std::reverse [C++]", "std::reverse_copy [C++]", "std::rotate [C++]", "std::rotate_copy [C++]", "std::search [C++]", "std::search_n [C++]", "std::set_difference [C++]", "std::set_intersection [C++]", "std::set_symmetric_difference [C++]", "std::set_union [C++]", "std::shuffle [C++]", "std::sort [C++]", "std::sort_heap [C++]", "std::stable_partition [C++]", "std::stable_sort [C++]", "std::swap_ranges [C++]", "std::transform [C++]", "std::unique [C++]", "std::unique_copy [C++]", "std::upper_bound [C++]", "std::copy [C++]", "std::copy_backward [C++]", "std::copy_n [C++]", "std::count [C++]", "std::equal [C++]", "std::fill [C++]", "std::fill_n [C++]", "std::find [C++]", "std::is_permutation [C++]", "std::lexicographical_compare [C++]", "std::move [C++]", "std::move_backward [C++]", "std::reverse [C++]", "std::rotate [C++]", "std::count_if [C++]", "std::partition_copy [C++]", "std::swap [C++]"]
11+
helpviewer_keywords: ["std::adjacent_find [C++]", "std::all_of [C++]", "std::any_of [C++]", "std::binary_search [C++]", "std::clamp [C++], "std::copy [C++]", "std::copy_backward [C++]", "std::copy_if [C++]", "std::copy_n [C++]", "std::equal [C++]", "std::equal_range [C++]", "std::fill [C++]", "std::fill_n [C++]", "std::find [C++]", "std::find_end [C++]", "std::find_first_of [C++]", "std::find_if [C++]", "std::find_if_not [C++]", "std::for_each [C++]", "std::for_each_n", "std::generate [C++]", "std::generate_n [C++]", "std::includes [C++]", "std::inplace_merge [C++]", "std::is_heap [C++]", "std::is_heap_until [C++]", "std::is_partitioned [C++]", "std::is_permutation [C++]", "std::is_sorted [C++]", "std::is_sorted_until [C++]", "std::iter_swap [C++]", "std::lexicographical_compare [C++]", "std::lower_bound [C++]", "std::make_heap [C++]", "std::max [C++]", "std::max_element [C++]", "std::merge [C++]", "std::min [C++]", "std::minmax [C++]", "std::minmax_element [C++]", "std::min_element [C++]", "std::mismatch [C++]", "std::move [C++]", "std::move_backward [C++]", "std::next_permutation [C++]", "std::none_of [C++]", "std::nth_element [C++]", "std::partial_sort [C++]", "std::partial_sort_copy [C++]", "std::partition [C++]", "std::partition_point [C++]", "std::pop_heap [C++]", "std::prev_permutation [C++]", "std::push_heap [C++]", "std::random_shuffle [C++]", "std::remove [C++]", "std::remove_copy [C++]", "std::remove_copy_if [C++]", "std::remove_if [C++]", "std::replace [C++]", "std::replace_copy [C++]", "std::replace_copy_if [C++]", "std::replace_if [C++]", "std::reverse [C++]", "std::reverse_copy [C++]", "std::rotate [C++]", "std::rotate_copy [C++]", "std::sample [C++], "std::search [C++]", "std::search_n [C++]", "std::set_difference [C++]", "std::set_intersection [C++]", "std::set_symmetric_difference [C++]", "std::set_union [C++]", "std::shuffle [C++]", "std::sort [C++]", "std::sort_heap [C++]", "std::stable_partition [C++]", "std::stable_sort [C++]", "std::swap_ranges [C++]", "std::transform [C++]", "std::unique [C++]", "std::unique_copy [C++]", "std::upper_bound [C++]", "std::copy [C++]", "std::copy_backward [C++]", "std::copy_n [C++]", "std::count [C++]", "std::equal [C++]", "std::fill [C++]", "std::fill_n [C++]", "std::find [C++]", "std::is_permutation [C++]", "std::lexicographical_compare [C++]", "std::move [C++]", "std::move_backward [C++]", "std::reverse [C++]", "std::rotate [C++]", "std::count_if [C++]", "std::partition_copy [C++]", "std::swap [C++]"]
1212
ms.workload: ["cplusplus"]
1313
---
1414
# <algorithm> functions
1515

1616
||||
1717
|-|-|-|
1818
|[move](#alg_move)|[adjacent_find](#adjacent_find)|[all_of](#all_of)|
19-
|[any_of](#any_of)|[binary_search](#binary_search)|[copy](#copy)|
20-
|[copy_backward](#copy_backward)|[copy_if](#copy_if)|[copy_n](#copy_n)|
21-
|[count](#count)|[count_if](#count_if)|[equal](#equal)|
22-
|[equal_range](#equal_range)|[fill](#fill)|[fill_n](#fill_n)|
23-
|[find](#find)|[find_end](#find_end)|[find_first_of](#find_first_of)|
24-
|[find_if](#find_if)|[find_if_not](#find_if_not)|[for_each](#for_each)|
25-
|[generate](#generate)|[generate_n](#generate_n)|[includes](#includes)|
26-
|[inplace_merge](#inplace_merge)|[is_heap](#is_heap)|[is_heap_until](#is_heap_until)|
27-
|[is_partitioned](#is_partitioned)|[is_permutation](#is_permutation)|[is_sorted](#is_sorted)|
28-
|[is_sorted_until](#is_sorted_until)|[iter_swap](#iter_swap)|[lexicographical_compare](#lexicographical_compare)|
29-
|[lower_bound](#lower_bound)|[make_heap](#make_heap)|[max](#max)|
30-
|[max_element](#max_element)|[merge](#merge)|[min](#min)|
31-
|[min_element](#min_element)|[minmax](#minmax)|[minmax_element](#minmax_element)|
32-
|[mismatch](#mismatch)|[move_backward](#move_backward)|[next_permutation](#next_permutation)|
33-
|[none_of](#none_of)|[nth_element](#nth_element)|[partial_sort](#partial_sort)|
34-
|[partial_sort_copy](#partial_sort_copy)|[partition](#partition)|[partition_copy](#partition_copy)|
35-
|[partition_point](#partition_point)|[pop_heap](#pop_heap)|[prev_permutation](#prev_permutation)|
36-
|[push_heap](#push_heap)|[random_shuffle](#random_shuffle)|[remove](#remove)|
37-
|[remove_copy](#remove_copy)|[remove_copy_if](#remove_copy_if)|[remove_if](#remove_if)|
38-
|[replace](#replace)|[replace_copy](#replace_copy)|[replace_copy_if](#replace_copy_if)|
39-
|[replace_if](#replace_if)|[reverse](#reverse)|[reverse_copy](#reverse_copy)|
40-
|[rotate](#rotate)|[rotate_copy](#rotate_copy)|[search](#search)|
19+
|[any_of](#any_of)|[binary_search](#binary_search)|[clamp](#clamp)|
20+
|[copy](#copy)|[copy_backward](#copy_backward)|[copy_if](#copy_if)|
21+
|[copy_n](#copy_n)|[count](#count)|[count_if](#count_if)|
22+
|[equal](#equal)|[equal_range](#equal_range)|[fill](#fill)|
23+
|[fill_n](#fill_n)|[find](#find)|[find_end](#find_end)|
24+
|[find_first_of](#find_first_of)|[find_if](#find_if)|[find_if_not](#find_if_not)|
25+
|[for_each](#for_each)|[for_each_n](#for_each_n)|[generate](#generate)|
26+
|[generate_n](#generate_n)|[includes](#includes)|[inplace_merge](#inplace_merge)|
27+
|[is_heap](#is_heap)|[is_heap_until](#is_heap_until)|[is_partitioned](#is_partitioned)|
28+
|[is_permutation](#is_permutation)|[is_sorted](#is_sorted)|[is_sorted_until](#is_sorted_until)|
29+
|[iter_swap](#iter_swap)|[lexicographical_compare](#lexicographical_compare)|
30+
|[lower_bound](#lower_bound)|
31+
|[make_heap](#make_heap)|[max](#max)|[max_element](#max_element)|
32+
|[merge](#merge)|[min](#min)|[min_element](#min_element)|
33+
|[minmax](#minmax)|[minmax_element](#minmax_element)|[mismatch](#mismatch)|
34+
|[move_backward](#move_backward)|[next_permutation](#next_permutation)|[none_of](#none_of)|
35+
|[nth_element](#nth_element)|[partial_sort](#partial_sort)|[partial_sort_copy](#partial_sort_copy)|
36+
|[partition](#partition)|[partition_copy](#partition_copy)|[partition_point](#partition_point)|
37+
|[pop_heap](#pop_heap)|[prev_permutation](#prev_permutation)|[push_heap](#push_heap)|
38+
|[random_shuffle](#random_shuffle)|[remove](#remove)|[remove_copy](#remove_copy)|
39+
|[remove_copy_if](#remove_copy_if)|[remove_if](#remove_if)|[replace](#replace)|
40+
|[replace_copy](#replace_copy)|[replace_copy_if](#replace_copy_if)|[replace_if](#replace_if)|
41+
|[reverse](#reverse)|[reverse_copy](#reverse_copy)|[rotate](#rotate)|
42+
|[rotate_copy](#rotate_copy)|[sample](#sample)|[search](#search)|
4143
|[search_n](#search_n)|[set_difference](#set_difference)|[set_intersection](#set_intersection)|
4244
|[set_symmetric_difference](#set_symmetric_difference)|[set_union](#set_union)|[sort](#sort)|
4345
|[sort_heap](#sort_heap)|[stable_partition](#stable_partition)|[stable_sort](#stable_sort)|
@@ -341,6 +343,15 @@ int main()
341343
}
342344
```
343345

346+
## <a name="clamp"></a> clamp
347+
348+
```cpp
349+
template<class T>
350+
constexpr const T& clamp(const T& v, const T& lo, const T& hi);
351+
template<class T, class Compare>
352+
constexpr const T& clamp(const T& v, const T& lo, const T& hi, Compare comp);
353+
```
354+
344355
## <a name="copy"></a> copy
345356

346357
Assigns the values of elements from a source range to a destination range, iterating through the source sequence of elements and assigning them new positions in a forward direction.
@@ -1776,6 +1787,16 @@ The average of the elements of v1 is:
17761787
Average ( v1mod2 ) = 10.
17771788
```
17781789

1790+
## <a name="for_each_n"></a> for_each_n
1791+
1792+
```cpp
1793+
template<class InputIterator, class Size, class Function>
1794+
InputIterator for_each_n(InputIterator first, Size n, Function f);
1795+
template<class ExecutionPolicy, class ForwardIterator, class Size, class Function>
1796+
ForwardIterator for_each_n(ExecutionPolicy&& exec,
1797+
ForwardIterator first, Size n, Function f);
1798+
```
1799+
17791800
## <a name="generate"></a> generate
17801801

17811802
Assigns the values generated by a function object to each element in a range.
@@ -6450,6 +6471,16 @@ int main() {
64506471
}
64516472
```
64526473

6474+
## <a name="sample"></a> sample
6475+
6476+
```cpp
6477+
template<class PopulationIterator, class SampleIterator,
6478+
class Distance, class UniformRandomBitGenerator>
6479+
SampleIterator sample(PopulationIterator first, PopulationIterator last,
6480+
SampleIterator out, Distance n,
6481+
UniformRandomBitGenerator&& g);
6482+
```
6483+
64536484
## <a name="search"></a> search
64546485

64556486
Searches for the first occurrence of a sequence within a target range whose elements are equal to those in a given sequence of elements or whose elements are equivalent in a sense specified by a binary predicate to the elements in the given sequence.

0 commit comments

Comments
 (0)