class BinaryOp, class UnaryOp >
OutputIt transform_exclusive_scan
( InputIt first, InputIt last, OutputIt d_first, T init,
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,
1) Computes the exclusive prefix sum using op.
For each integer
iin
[
â0â,
std::distance(first, last))
, performs the following operations in order:
[
first,
iter)
in order by unary_op, where iter is the next ith iterator of first.2) Same as (1), but executed according to policy.
This overload participates in overload resolution only if all following conditions are satisfied:
The generalized noncommutative sum of a sequence of elements over a binary operation binary_op is defined as follows:
The result is non-deterministic if the binary_op is not associative (such as floating-point addition).
If any of the following values is not convertible to T
, the program is ill-formed:
If any of the following conditions is satisfied, the behavior is undefined:
T
is not MoveConstructible.[
first,
last)
.[
first,
last]
.InputIt
must meet the requirements of LegacyInputIterator. -OutputIt
must meet the requirements of LegacyOutputIterator. -ForwardIt1, ForwardIt2
must meet the requirements of LegacyForwardIterator. [edit] Return value
Iterator to the element past the last element written.
[edit] ComplexityGiven \(\scriptsize N\)N as std::distance(first, last):
1,2) \(\scriptsize O(N)\)O(N) applications of unary_op and binary_op respectively.
[edit] ExceptionsThe overload with a template parameter named ExecutionPolicy
reports errors as follows:
ExecutionPolicy
is one of the standard policies, std::terminate is called. For any other ExecutionPolicy
, the behavior is implementation-defined.unary_op is never applied to init.
[edit] 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'; }
Output:
10 times exclusive sum: 0 30 40 80 90 140 230 250 10 times inclusive sum: 30 40 80 90 140 230 250 310[edit] See also
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4