1. algorithm
— Generic algorithms¶
This module contains generic algorithms. Someof them are modeled on the
algorithms in the standard library header <algorithm>
while some other
ones work on specific objects.
1.1. Range algorithms¶
These algorithms generally operate on pairs of iterators.
-
UnaryOperation
for_each
(InputIt first, InputIt last, UnaryOperation unary_op)¶ This function is a mere wrapper around
std::for_each
which works exactly the same way. It is provided for consistency with its binary version.
-
BinaryOperation
for_each
(InputIt1 first1, InputIt1 last1, InputIt2 first2, BinaryOperation binary_op)¶ This function is a binary equivalent to
std::for_each
. It applies a given operation to the elements obtained by dereferencing the iterators in the ranges[first1, last1)
and[first2, first2 + last1 - first1)
.
-
auto
min_element_and_is_sorted
(ForwardIt first, ForwardIt last, Compare comp)¶ This function is a fused algorithm which computes the smallest element in a range of elements and returns the corresponding iterator as well as a boolean value corresponding to whether the range is sorted or not. The return type is an unnamed
struct
with the following structure:struct { ForwardIt min; bool is_sorted; };
The algorithm should perform exactly
last - first
comparisons. If the comparatorcomp
is omitted, the algorithm uses a default-constructed instance ofstd::less<>
.
-
auto
max_element_and_is_sorted
(ForwardIt first, ForwardIt last, Compare comp)¶ This function is a fused algorithm which computes the greatest element in a range of elements and returns the corresponding iterator as well as a boolean value corresponding to whether the range is sorted or not. The return type is an unnamed
struct
with the following structure:struct { ForwardIt max; bool is_sorted; };
The algorithm should perform exactly
last - first
comparisons. If the comparatorcomp
is omitted, the algorithm uses a default-constructed instance ofstd::less<>
.
-
auto
min_element_and_is_sorted_until
(ForwardIt first, ForwardIt last, Compare comp)¶ This function is a fused algorithm which computes the smallest element in a range of elements and returns the corresponding iterator as well as another one corresponding to one past the last sorted element. The return type is an unnamed
struct
with the following structure:struct { ForwardIt min; ForwardIt until; };
The algorithm should perform exactly
last - first
comparisons. Ifcomp
is omitted, the algorithm uses a default-constructed instance ofstd::less<>
.
-
auto
max_element_and_is_sorted_until
(ForwardIt first, ForwardIt last, Compare comp)¶ This function is a fused algorithm which computes the greatest element in a range of elements and returns the corresponding iterator as well as another one corresponding to one past the last sorted element. The return type is an unnamed
struct
with the following structure:struct { ForwardIt max; ForwardIt until; };
The algorithm should perform exactly
last - first
comparisons. Ifcomp
is omitted, the algorithm uses a default-constructed instance ofstd::less<>
.
1.2. Other algorithms¶
Miscellaneous algorithms, not range-based:
-
int
compare
(const T &lhs, const U &rhs)¶ This functions compares the values
lhs
andrhs
and returns either 0, 1 or -1 when the values are respectively in order, equal or in reverse order. It has efficient specializations for some standard types.