std::transform_exclusive_scan
: cppreference.com
<tbody>
</tbody>
<tbody class="t-dcl-rev t-dcl-rev-num ">
</tbody><tbody>
</tbody>
| (1) | ||
template< class InputIt, class OutputIt, class T, class BinaryOperation, class UnaryOperation> OutputIt transform_exclusive_scan( InputIt first, InputIt last, OutputIt d_first, T init, BinaryOperation binary_op, UnaryOperation unary_op); |
(C++17) (C++20) |
|
template< class InputIt, class OutputIt, class T, class BinaryOperation, class UnaryOperation> constexpr OutputIt transform_exclusive_scan( InputIt first, InputIt last, OutputIt d_first, T init, BinaryOperation binary_op, UnaryOperation unary_op); |
(C++20) | |
template< class ExecutionPolicy, class ForwardIt1, class ForwardIt2, class T, class BinaryOperation, class UnaryOperation > ForwardIt2 transform_exclusive_scan( ExecutionPolicy&& policy, ForwardIt1 first, ForwardIt1 last, ForwardIt2 d_first, T init, BinaryOperation binary_op, UnaryOperation unary_op ); |
(2) | (C++17) |
[first, last) unary_op init binary_op exclusive prefix sum d_first exclusive i i
[first, first + (i - d_first)) j binary_op init, unary_op(*j)... [d_first, d_first + (last - first)) i
GNSUM(op, a
1, ..., a
N)
- N=1 a
1 - N > 1 1 < K+1 = M N K op(GNSUM(op, a
1, ..., a
K), GNSUM(op, a
M, ..., a
N))
binary_op
(2) policy std::is_execution_policy_v<std::decay_t<ExecutionPolicy>> true
unary_op binary_op [first, last) [d_first, d_first + (last - first)) ()
| first, last | - | |
| d_first | - | first
|
| policy | - | |
| init | - | |
| unary_op | - | FunctionObject binary_op
|
| binary_op | - | unary_op binary_op init FunctionObject
|
-InputIt LegacyInputIterator
| ||
-OutputIt LegacyOutputIterator
| ||
-ForwardIt1, ForwardIt2 LegacyForwardIterator
| ||
-T MoveConstructible binary_op(init, unary_op(*first))binary_op(init, init) binary_op(unary_op(*first), unary_op(*first)) T
| ||
O(last - first) binary_op unary_op
ExecutionPolicy
-
ExecutionPolicystd::terminateExecutionPolicy - std::bad_alloc
unary_op init
Run this code
#include <functional>
#include <iostream>
#include <iterator>
#include <numeric>
#include <vector>
int times_10(int x)
{
return x * 10;
}
int main()
{
std::vector data {3, 1, 4, 1, 5, 9, 2, 6};
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);
}
:
10 times exclusive sum: 0 30 40 80 90 140 230 250
10 times inclusive sum: 30 40 80 90 140 230 250 310
| () | |
(C++17) |
std::inclusive_scan i i () |
(C++17) |
inclusive scan () |