| 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 BinaryOp,class UnaryOp> | (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,class UnaryOp,class T> | (3) | (since C++17) (constexpr since C++20) |
template<class ExecutionPolicy, class ForwardIt1,class ForwardIt2, | (4) | (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.[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:
The result is non-deterministic if thebinary_op is not associative (such as floating-point addition).
For overloads(1,2), ifbinary_op(unary_op(*first), unary_op(*first)) is not convertible to thevalue type ofdecltype(first), the program is ill-formed.
For overloads(3,4), 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 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.unary_op is never applied toinit.
The parameterinit appears last, differing fromstd::transform_exclusive_scan, because it is optional for this function.
#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] | |
| applies a function to a range of elements, storing results in a destination range (function template)[edit] | |
(C++17) | similar tostd::partial_sum, includes theith input element in theith sum (function template)[edit] |
(C++17) | applies an invocable, then calculates exclusive scan (function template)[edit] |