Constrained algorithms and algorithms on ranges(C++20) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Constrained algorithms, e.g.ranges::copy,ranges::sort, ... | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Execution policies(C++17) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Numeric operations | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Operations on uninitialized memory | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Common mathematical functions | |||||||||||||||||||||||||||||||
Mathematical special functions(C++17) | |||||||||||||||||||||||||||||||
Mathematical constants(C++20) | |||||||||||||||||||||||||||||||
Basic linear algebra algorithms(C++26) | |||||||||||||||||||||||||||||||
Data-parallel types (SIMD)(C++26) | |||||||||||||||||||||||||||||||
Floating-point environment(C++11) | |||||||||||||||||||||||||||||||
Complex numbers | |||||||||||||||||||||||||||||||
Numeric array (valarray ) | |||||||||||||||||||||||||||||||
Pseudo-random number generation | |||||||||||||||||||||||||||||||
Bit manipulation(C++20) | |||||||||||||||||||||||||||||||
Saturation arithmetic(C++26) | |||||||||||||||||||||||||||||||
Factor operations | |||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||
Interpolations | |||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||
Generic numeric operations | |||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||
C-style checked integer arithmetic | |||||||||||||||||||||||||||||||
|
Defined in header <numeric> | ||
template<class InputIt,class OutputIt> OutputIt inclusive_scan( InputIt first, InputIt last, | (1) | (since C++17) (constexpr since C++20) |
template<class ExecutionPolicy, class ForwardIt1,class ForwardIt2> | (2) | (since C++17) |
template<class InputIt,class OutputIt,class BinaryOp> OutputIt inclusive_scan( InputIt first, InputIt last, | (3) | (since C++17) (constexpr since C++20) |
template<class ExecutionPolicy, class ForwardIt1,class ForwardIt2,class BinaryOp> | (4) | (since C++17) |
template<class InputIt,class OutputIt, class BinaryOp,class T> | (5) | (since C++17) (constexpr since C++20) |
template<class ExecutionPolicy, class ForwardIt1,class ForwardIt2, | (6) | (since C++17) |
[
0,
std::distance(first, last))
, performs the following operations in order:[
first,
iter]
in order, whereiter is the nextith iterator offirst.[
first,
iter]
in order.std::is_execution_policy_v<std::decay_t<ExecutionPolicy>> istrue. | (until C++20) |
std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>> istrue. | (since C++20) |
Thegeneralized, noncommutative sum of a sequence of elements over a binary operationbinary_op is defined as follows:
Givenbinary_op as the actual binary operation:
T
, the program is ill-formed:T
is notMoveConstructible.[
first,
last)
.[
first,
last]
.Contents |
first, last | - | the pair of iterators defining the sourcerange of elements to sum |
d_first | - | the beginning of the destinationrange; may be equal tofirst |
policy | - | theexecution policy to use |
init | - | the initial value |
op | - | binaryFunctionObject that will be applied in to the result of dereferencing the input iterators, the results of otherop, andinit (if provided) |
Type requirements | ||
-InputIt must meet the requirements ofLegacyInputIterator. | ||
-OutputIt must meet the requirements ofLegacyOutputIterator. | ||
-ForwardIt1, ForwardIt2 must meet the requirements ofLegacyForwardIterator. |
Iterator to the element past the last element written.
Given\(\scriptsize N\)N asstd::distance(first, last):
The overloads with a template parameter namedExecutionPolicy
report errors as follows:
ExecutionPolicy
is one of thestandard policies,std::terminate is called. For any otherExecutionPolicy
, 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 25Inclusive sum: 3 4 8 9 14 23 25 31 Exclusive product: 1 3 3 12 12 60 540 1080Inclusive product: 3 3 12 12 60 540 1080 6480
computes the differences between adjacent elements in a range (function template)[edit] | |
sums up or folds a range of elements (function template)[edit] | |
computes the partial sum of a range of elements (function template)[edit] | |
(C++17) | applies an invocable, then calculates inclusive scan (function template)[edit] |
(C++17) | similar tostd::partial_sum, excludes theith input element from theith sum (function template)[edit] |