OutputIt exclusive_scan( InputIt first, InputIt last,
class ForwardIt1, class ForwardIt2, class T >
ForwardIt2 exclusive_scan( ExecutionPolicy&& policy,
ForwardIt1 first, ForwardIt1 last,
class T, class BinaryOp >
OutputIt exclusive_scan( InputIt first, InputIt last,
class ForwardIt1, class ForwardIt2,
class T, class BinaryOp >
ForwardIt2 exclusive_scan( ExecutionPolicy&& policy,
ForwardIt1 first, ForwardIt1 last,
Equivalent to
exclusive_scan(first, last, d_first, init, std::plus<>().
3) 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, where iter is the next ith iterator of first.2,4) Same as (1,3), but executed according to policy.
These overloads participate 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:
Given binary_op as the actual binary operation:
T
, the program is ill-formed: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
std::plus<>().
3,4) \(\scriptsize O(N)\)O(N) applications of op.
[edit] ExceptionsThe overloads with a template parameter named ExecutionPolicy
report errors as follows:
ExecutionPolicy
is one of the standard policies, std::terminate is called. For any other ExecutionPolicy
, the behavior is implementation-defined.#include <functional> #include <iostream> #include <iterator> #include <numeric> #include <vector> int main() { std::vector data{3, 1, 4, 1, 5, 9, 2, 6}; std::cout << "Exclusive sum: "; std::exclusive_scan(data.begin(), data.end(), std::ostream_iterator<int>(std::cout, " "), 0); std::cout << "\nInclusive sum: "; std::inclusive_scan(data.begin(), data.end(), std::ostream_iterator<int>(std::cout, " ")); std::cout << "\n\nExclusive product: "; std::exclusive_scan(data.begin(), data.end(), std::ostream_iterator<int>(std::cout, " "), 1, std::multiplies<>{}); std::cout << "\nInclusive product: "; std::inclusive_scan(data.begin(), data.end(), std::ostream_iterator<int>(std::cout, " "), std::multiplies<>{}); }
Output:
Exclusive sum: 0 3 4 8 9 14 23 25 Inclusive sum: 3 4 8 9 14 23 25 31 Exclusive product: 1 3 3 12 12 60 540 1080 Inclusive product: 3 3 12 12 60 540 1080 6480[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