Add the transform examples for the std::reduce section.

This commit is contained in:
Anthony Calandra
2023-02-20 19:57:45 -05:00
parent abab8bb1a3
commit 5a9e63549e
2 changed files with 18 additions and 0 deletions

View File

@@ -560,6 +560,15 @@ std::reduce(std::cbegin(a), std::cend(a)); // == 6
// Using a custom binary op:
std::reduce(std::cbegin(a), std::cend(a), 1, std::multiplies<>{}); // == 6
```
Additionally you can specify transformations for reducers:
```c++
std::transform_reduce(std::cbegin(a), std::cend(a), 0, std::plus<>{}, times_ten); // == 60
const std::array<int, 3> b{ 1, 2, 3 };
const auto product_times_ten = [](const auto a, const auto b) { return a * b * 10; };
std::transform_reduce(std::cbegin(a), std::cend(a), std::cbegin(b), 0, std::plus<>{}, product_times_ten); // == 140
```
### Prefix sum algorithms
Support for prefix sums (both inclusive and exclusive scans) along with transformations.