Conventions
To use the algorithms, you have to keep a few rules in your head.
The algorithms are defined in various headers.
<algorithm>
- Contains the general algorithms.
<numeric>
- Contains the numeric algorithms.
Many of the algorithms have the name suffix _if
and _copy
.
_if
- The algorithm can be parametrized by a predicate.
_copy
- The algorithm copies its elements in another range.
Algorithms like auto num= std::count(InpIt first, InpIt last, const T& val)
return the number of elements that are equal to val
. num
is of type iterator_traits<InpIt>::difference_type
. You have the guarantee that num
is sufficient to hold the result. Because of the automatic return type deduction with auto
, the compiler will give you the right types.