std::transform_exclusive_scan
Min standard notice:
Header: <numeric>
- Computes the exclusive prefix sum using op.
# Declarations
template< class InputIt, class OutputIt, class T,
class BinaryOp, class UnaryOp >
OutputIt transform_exclusive_scan
( InputIt first, InputIt last, OutputIt d_first, T init,
BinaryOp binary_op, UnaryOp unary_op );
(since C++17) (constexpr since C++20)
template< class ExecutionPolicy,
class ForwardIt1, class ForwardIt2, class T,
class BinaryOp, class UnaryOp >
ForwardIt2 transform_exclusive_scan
( ExecutionPolicy&& policy,
ForwardIt1 first, ForwardIt1 last, ForwardIt2 d_first, T init,
BinaryOp binary_op, UnaryOp unary_op );
(since C++17)
# Parameters
first, last: the range of elements to sumd_first: the beginning of the destination range, may be equal to firstpolicy: the execution policy to useinit: the initial valueunary_op: unary FunctionObject that will be applied to each element of the input range. The return type must be acceptable as input to binary_op.binary_op: binary FunctionObject that will be applied in to the result of unary_op, the results of other binary_op, and init.
# Return value
Iterator to the element past the last element written.
# Notes
unary_op is never applied to init.
# Example
#include <functional>
#include <iostream>
#include <iterator>
#include <numeric>
#include <vector>
int main()
{
std::vector data{3, 1, 4, 1, 5, 9, 2, 6};
auto times_10 = [](int x) { return x * 10; };
std::cout << "10 times exclusive sum: ";
std::transform_exclusive_scan(data.begin(), data.end(),
std::ostream_iterator<int>(std::cout, " "),
0, std::plus<int>{}, times_10);
std::cout << "\n10 times inclusive sum: ";
std::transform_inclusive_scan(data.begin(), data.end(),
std::ostream_iterator<int>(std::cout, " "),
std::plus<int>{}, times_10);
std::cout << '\n';
}