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,class T, class BinaryOp,class UnaryOp> | (1) | (since C++17) (constexpr since C++20) |
template<class ExecutionPolicy, class ForwardIt1,class ForwardIt2,class T, | (2) | (since C++17) |
[
0,
std::distance(first, last))
, performs the following operations in order:[
first,
iter)
in order byunary_op, whereiter is the nextith iterator offirst.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:
The result is non-deterministic if thebinary_op is not associative (such as floating-point addition).
If any of the following values is not convertible toT
, the program is ill-formed:
If any of the following conditions is satisfied, the behavior is undefined:
T
is notMoveConstructible.[
first,
last)
.[
first,
last]
.Contents |
first, last | - | the pair of iterators defining therange of elements to sum |
d_first | - | the beginning of the destination range, may be equal tofirst |
policy | - | theexecution policy to use |
init | - | the initial value |
unary_op | - | unaryFunctionObject that will be applied to each element of the input range. The return type must be acceptable as input tobinary_op. |
binary_op | - | binaryFunctionObject that will be applied in to the result ofunary_op, the results of otherbinary_op, andinit. |
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 overload with a template parameter namedExecutionPolicy
reports errors as follows:
ExecutionPolicy
is one of thestandard policies,std::terminate is called. For any otherExecutionPolicy
, the behavior is implementation-defined.unary_op is never applied toinit.
#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
computes the partial sum of a range of elements (function template)[edit] | |
(C++17) | similar tostd::partial_sum, excludes theith input element from theith sum (function template)[edit] |
(C++17) | applies an invocable, then calculates inclusive scan (function template)[edit] |