La librairie standard C++

modifier

La librairie standard C++ est l'ensemble des fonctions et des classes normalisées dans le standard ISO, et qui sont fournies avec tout compilateur C++. Ces fonctions et classes reposent sur l'utilisation des templates, une fonctionnalité très présente dans cette bibliothèque.

Quelques fonctionnalités de base

modifier

Itérateurs et algorithmes

modifier

Standard library header <algorithm>

modifier

C++


Standard Library headers


This header is part of the algorithm library.

Functions

modifier
Non-modifying sequence operations
modifier
all_ofany_ofnone_of

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

for_each applies a function to a range of elements

(function template)

for_each_n

(C++17)

applies a function object to the first n elements of a sequence

(function template)

countcount_if returns the number of elements satisfying specific criteria

(function template)

mismatch finds the first position where two ranges differ

(function template)

findfind_iffind_if_not

(C++11)

finds the first element satisfying specific criteria

(function template)

find_end finds the last sequence of elements in a certain range

(function template)

find_first_of searches for any one of a set of elements

(function template)

adjacent_find finds the first two adjacent items that are equal (or satisfy a given predicate)

(function template)

search searches for a range of elements

(function template)

search_n searches a range for a number of consecutive copies of an element

(function template)

Modifying sequence operations
modifier
copycopy_if

(C++11)

copies a range of elements to a new location

(function template)

copy_n

(C++11)

copies a number of elements to a new location

(function template)

copy_backward copies a range of elements in backwards order

(function template)

move

(C++11)

moves a range of elements to a new location

(function template)

move_backward

(C++11)

moves a range of elements to a new location in backwards order

(function template)

fill copy-assigns the given value to every element in a range

(function template)

fill_n copy-assigns the given value to N elements in a range

(function template)

transform applies a function to a range of elements, storing results in a destination range

(function template)

generate assigns the results of successive function calls to every element in a range

(function template)

generate_n assigns the results of successive function calls to N elements in a range

(function template)

removeremove_if removes elements satisfying specific criteria

(function template)

remove_copyremove_copy_if copies a range of elements omitting those that satisfy specific criteria

(function template)

replacereplace_if replaces all values satisfying specific criteria with another value

(function template)

replace_copyreplace_copy_if copies a range, replacing elements satisfying specific criteria with another value

(function template)

swap swaps the values of two objects

(function template)

swap_ranges swaps two ranges of elements

(function template)

iter_swap swaps the elements pointed to by two iterators

(function template)

reverse reverses the order of elements in a range

(function template)

reverse_copy creates a copy of a range that is reversed

(function template)

rotate rotates the order of elements in a range

(function template)

rotate_copy copies and rotate a range of elements

(function template)

shift_leftshift_right

(C++20)

shifts elements in a range

(function template)

random_shuffleshuffle

(until C++17)(C++11)

randomly re-orders elements in a range

(function template)

sample

(C++17)

selects n random elements from a sequence

(function template)

unique removes consecutive duplicate elements in a range

(function template)

unique_copy creates a copy of some range of elements that contains no consecutive duplicates

(function template)

Partitioning operations
modifier
is_partitioned

(C++11)

determines if the range is partitioned by the given predicate

(function template)

partition divides a range of elements into two groups

(function template)

partition_copy

(C++11)

copies a range dividing the elements into two groups

(function template)

stable_partition divides elements into two groups while preserving their relative order

(function template)

partition_point

(C++11)

locates the partition point of a partitioned range

(function template)

Sorting operations
modifier
is_sorted

(C++11)

checks whether a range is sorted into ascending order

(function template)

is_sorted_until

(C++11)

finds the largest sorted subrange

(function template)

sort sorts a range into ascending order

(function template)

partial_sort sorts the first N elements of a range

(function template)

partial_sort_copy copies and partially sorts a range of elements

(function template)

stable_sort sorts a range of elements while preserving order between equal elements

(function template)

nth_element partially sorts the given range making sure that it is partitioned by the given element

(function template)

Binary search operations (on sorted ranges)
modifier
lower_bound returns an iterator to the first element not less than the given value

(function template)

upper_bound returns an iterator to the first element greater than a certain value

(function template)

binary_search determines if an element exists in a certain range

(function template)

equal_range returns range of elements matching a specific key

(function template)

Other operations on sorted ranges
modifier
merge merges two sorted ranges

(function template)

inplace_merge merges two ordered ranges in-place

(function template)

Set operations (on sorted ranges)
modifier
includes returns true if one sequence is a subsequence of another

(function template)

set_difference computes the difference between two sets

(function template)

set_intersection computes the intersection of two sets

(function template)

set_symmetric_difference computes the symmetric difference between two sets

(function template)

set_union computes the union of two sets

(function template)

Heap operations
modifier
is_heap

(C++11)

checks if the given range is a max heap

(function template)

is_heap_until

(C++11)

finds the largest subrange that is a max heap

(function template)

make_heap creates a max heap out of a range of elements

(function template)

push_heap adds an element to a max heap

(function template)

pop_heap removes the largest element from a max heap

(function template)

sort_heap turns a max heap into a range of elements sorted in ascending order

(function template)

Minimum/maximum operations
modifier
max returns the greater of the given values

(function template)

max_element returns the largest element in a range

(function template)

min returns the smaller of the given values

(function template)

min_element returns the smallest element in a range

(function template)

minmax

(C++11)

returns the smaller and larger of two elements

(function template)

minmax_element

(C++11)

returns the smallest and the largest elements in a range

(function template)

clamp

(C++17)

clamps a value between a pair of boundary values

(function template)

Comparison operations
modifier
equal determines if two sets of elements are the same

(function template)

lexicographical_compare returns true if one range is lexicographically less than another

(function template)

lexicographical_compare_three_way

(C++20)

compares two ranges using three-way comparison

(function template)

Permutation operations
modifier
is_permutation

(C++11)

determines if a sequence is a permutation of another sequence

(function template)

next_permutation generates the next greater lexicographic permutation of a range of elements

(function template)

prev_permutation generates the next smaller lexicographic permutation of a range of elements

(function template)

Range Algorithms

modifier
Defined in namespace std::ranges
Non-modifying sequence operations
modifier
ranges::all_ofranges::any_ofranges::none_of

(C++20)(C++20)(C++20)

checks if a predicate is true for all, any or none of the elements in a range

(niebloid)

ranges::for_each

(C++20)

applies a function to a range of elements

(niebloid)

ranges::countranges::count_if

(C++20)(C++20)

returns the number of elements satisfying specific criteria

(niebloid)

ranges::mismatch

(C++20)

finds the first position where two ranges differ

(niebloid)

ranges::findranges::find_ifranges::find_if_not

(C++20)(C++20)(C++20)

finds the first element satisfying specific criteria

(niebloid)

ranges::find_end

(C++20)

finds the last sequence of elements in a certain range

(niebloid)

ranges::find_first_of

(C++20)

searches for any one of a set of elements

(niebloid)

ranges::adjacent_find

(C++20)

finds the first two adjacent items that are equal (or satisfy a given predicate)

(niebloid)

ranges::search

(C++20)

searches for a range of elements

(niebloid)

ranges::search_n

(C++20)

searches for a number consecutive copies of an element in a range

(niebloid)

Modifying sequence operations
modifier
ranges::copyranges::copy_if

(C++20)(C++20)

copies a range of elements to a new location

(niebloid)

ranges::copy_n

(C++20)

copies a number of elements to a new location

(niebloid)

ranges::copy_backward

(C++20)

copies a range of elements in backwards order

(niebloid)

ranges::move

(C++20)

moves a range of elements to a new location

(niebloid)

ranges::move_backward

(C++20)

moves a range of elements to a new location in backwards order

(niebloid)

ranges::fill

(C++20)

assigns a range of elements a certain value

(niebloid)

ranges::fill_n

(C++20)

assigns a value to a number of elements

(niebloid)

ranges::transform

(C++20)

applies a function to a range of elements

(niebloid)

ranges::generate

(C++20)

saves the result of a function in a range

(niebloid)

ranges::generate_n

(C++20)

saves the result of N applications of a function

(niebloid)

ranges::removeranges::remove_if

(C++20)(C++20)

removes elements satisfying specific criteria

(niebloid)

ranges::remove_copyranges::remove_copy_if

(C++20)(C++20)

copies a range of elements omitting those that satisfy specific criteria

(niebloid)

ranges::replaceranges::replace_if

(C++20)(C++20)

replaces all values satisfying specific criteria with another value

(niebloid)

ranges::replace_copyranges::replace_copy_if

(C++20)(C++20)

copies a range, replacing elements satisfying specific criteria with another value

(niebloid)

ranges::swap_ranges

(C++20)

swaps two ranges of elements

(niebloid)

ranges::reverse

(C++20)

reverses the order of elements in a range

(niebloid)

ranges::reverse_copy

(C++20)

creates a copy of a range that is reversed

(niebloid)

ranges::rotate

(C++20)

rotates the order of elements in a range

(niebloid)

ranges::rotate_copy

(C++20)

copies and rotate a range of elements

(niebloid)

ranges::shuffle

(C++20)

randomly re-orders elements in a range

(niebloid)

ranges::unique

(C++20)

removes consecutive duplicate elements in a range

(niebloid)

ranges::unique_copy

(C++20)

creates a copy of some range of elements that contains no consecutive duplicates

(niebloid)

Partitioning operations
modifier
ranges::is_partitioned

(C++20)

determines if the range is partitioned by the given predicate

(niebloid)

ranges::partition

(C++20)

divides a range of elements into two groups

(niebloid)

ranges::partition_copy

(C++20)

copies a range dividing the elements into two groups

(niebloid)

ranges::stable_partition

(C++20)

divides elements into two groups while preserving their relative order

(niebloid)

ranges::partition_point

(C++20)

locates the partition point of a partitioned range

(niebloid)

Sorting operations
modifier
ranges::is_sorted

(C++20)

checks whether a range is sorted into ascending order

(niebloid)

ranges::is_sorted_until

(C++20)

finds the largest sorted subrange

(niebloid)

ranges::sort

(C++20)

sorts a range into ascending order

(niebloid)

ranges::partial_sort

(C++20)

sorts the first N elements of a range

(niebloid)

ranges::partial_sort_copy

(C++20)

copies and partially sorts a range of elements

(niebloid)

ranges::stable_sort

(C++20)

sorts a range of elements while preserving order between equal elements

(niebloid)

ranges::nth_element

(C++20)

partially sorts the given range making sure that it is partitioned by the given element

(niebloid)

Binary search operations (on sorted ranges)
modifier
ranges::lower_bound

(C++20)

returns an iterator to the first element not less than the given value

(niebloid)

ranges::upper_bound

(C++20)

returns an iterator to the first element greater than a certain value

(niebloid)

ranges::binary_search

(C++20)

determines if an element exists in a certain range

(niebloid)

ranges::equal_range

(C++20)

returns range of elements matching a specific key

(niebloid)

Other operations on sorted ranges
modifier
ranges::merge

(C++20)

merges two sorted ranges

(niebloid)

ranges::inplace_merge

(C++20)

merges two ordered ranges in-place

(niebloid)

Set operations (on sorted ranges)
modifier
ranges::includes

(C++20)

returns true if one sequence is a subsequence of another

(niebloid)

ranges::set_difference

(C++20)

computes the difference between two sets

(niebloid)

ranges::set_intersection

(C++20)

computes the intersection of two sets

(niebloid)

ranges::set_symmetric_difference

(C++20)

computes the symmetric difference between two sets

(niebloid)

ranges::set_union

(C++20)

computes the union of two sets

(niebloid)

Heap operations
modifier
ranges::is_heap

(C++20)

checks if the given range is a max heap

(niebloid)

ranges::is_heap_until

(C++20)

finds the largest subrange that is a max heap

(niebloid)

ranges::make_heap

(C++20)

creates a max heap out of a range of elements

(niebloid)

ranges::push_heap

(C++20)

adds an element to a max heap

(niebloid)

ranges::pop_heap

(C++20)

removes the largest element from a max heap

(niebloid)

ranges::sort_heap

(C++20)

turns a max heap into a range of elements sorted in ascending order

(niebloid)

Minimum/maximum operations
modifier
ranges::max

(C++20)

returns the greater of the given values

(niebloid)

ranges::max_element

(C++20)

returns the largest element in a range

(niebloid)

ranges::min

(C++20)

returns the smaller of the given values

(niebloid)

ranges::min_element

(C++20)

returns the smallest element in a range

(niebloid)

ranges::minmax

(C++20)

returns the smaller and larger of two elements

(niebloid)

ranges::minmax_element

(C++20)

returns the smallest and the largest elements in a range

(niebloid)

Comparison operations
modifier
ranges::equal

(C++20)

determines if two sets of elements are the same

(niebloid)

ranges::lexicographical_compare

(C++20)

returns true if one range is lexicographically less than another

(niebloid)

Permutation operations
modifier
ranges::is_permutation

(C++20)

determines if a sequence is a permutation of another sequence

(niebloid)

ranges::next_permutation

(C++20)

generates the next greater lexicographic permutation of a range of elements

(niebloid)

ranges::prev_permutation

(C++20)

generates the next smaller lexicographic permutation of a range of elements

(niebloid)

Conteneurs

modifier
<array>

(C++11)

std::array container
<vector> std::vector container
<deque> std::deque container
<list> std::list container
<forward_list>

(C++11)

std::forward_list container
<set> std::set and std::multiset associative containers
<map> std::map and std::multimap associative containers
<unordered_set>

(C++11)

std::unordered_set and std::unordered_multiset unordered associative containers
<unordered_map>

(C++11)

std::unordered_map and std::unordered_multimap unordered associative containers
<stack> std::stack container adaptor
<queue> std::queue and std::priority_queue container adaptors
<span>

(C++20)

std::span view

[1]

  1. C++ Standard Library headers - cppreference.com