The New Algorithms
This lesson gives an overview of the new algorithms that are a part of C++17.
The new algorithms are in the std
namespace. std::for_each
and std::for_each_n
require the header <algorithm>
, but the remaining 6 algorithms require the header <numeric>
.
Here is an overview of the new algorithms:
Algorithm | Description |
---|---|
std::for_each |
Applies a unary callable to the range. |
std::for_each_n |
Applies a unary callable to the first n elements of the range. |
std::exclusive_scan |
Applies from the left a binary callable up to the ith (exclusive) element of the range. The left argument of the callable is the previous result. Stores intermediate results. |
std::inclusive_scan |
Applies from the left a binary callable up to the ith (inclusive) element of the range. The left argument of the callable is the previous result. Stores intermediate results. |
std::transform_exclusive_scan |
First applies a unary callable to the range and then applies std::exclusive_scan . |
std::transform_inclusive_scan |
First applies a unary callable to the range and then applies std::inclusive_scan . |
std::reduce |
Applies from the left a binary callable to the range. |
std::transform_reduce |
Applies first a unary callable to the range and then std::reduce . |
Admittedly, this description is not easy to digest; therefore, I will first present an exhaustive example and then write about the functional heritage of these functions. I will ignore the new std::for_each
algorithm. In contrast to the C++98 variant that returns a unary function, the additional C++17 variant returns nothing.
As far as I know, at the time this course is being written (June 2017) there is no standard-conforming implementation of the parallel STL available. Therefore, I used the HPX implementation to produce the output. The HPX (High-Performance ParalleX) is a framework that is a general-purpose C++ runtime system for parallel and distributed applications of any scale.
Get hands-on with 1400+ tech skills courses.