libstdc++
Generalized Numeric operations
Collaboration diagram for Generalized Numeric operations:

Functions

template<typename _InputIterator , typename _Tp >
constexpr _Tp std::accumulate (_InputIterator __first, _InputIterator __last, _Tp __init)
 
template<typename _InputIterator , typename _Tp , typename _BinaryOperation >
constexpr _Tp std::accumulate (_InputIterator __first, _InputIterator __last, _Tp __init, _BinaryOperation __binary_op)
 
template<typename _InputIterator , typename _OutputIterator >
constexpr _OutputIterator std::adjacent_difference (_InputIterator __first, _InputIterator __last, _OutputIterator __result)
 
template<typename _InputIterator , typename _OutputIterator , typename _BinaryOperation >
constexpr _OutputIterator std::adjacent_difference (_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryOperation __binary_op)
 
template<typename _InputIterator , typename _OutputIterator , typename _Tp >
constexpr _OutputIterator std::exclusive_scan (_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Tp __init)
 
template<typename _InputIterator , typename _OutputIterator , typename _Tp , typename _BinaryOperation >
constexpr _OutputIterator std::exclusive_scan (_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Tp __init, _BinaryOperation __binary_op)
 
template<typename _InputIterator , typename _OutputIterator >
constexpr _OutputIterator std::inclusive_scan (_InputIterator __first, _InputIterator __last, _OutputIterator __result)
 
template<typename _InputIterator , typename _OutputIterator , typename _BinaryOperation >
constexpr _OutputIterator std::inclusive_scan (_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryOperation __binary_op)
 
template<typename _InputIterator , typename _OutputIterator , typename _BinaryOperation , typename _Tp >
constexpr _OutputIterator std::inclusive_scan (_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryOperation __binary_op, _Tp __init)
 
template<typename _InputIterator1 , typename _InputIterator2 , typename _Tp >
constexpr _Tp std::inner_product (_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _Tp __init)
 
template<typename _InputIterator1 , typename _InputIterator2 , typename _Tp , typename _BinaryOperation1 , typename _BinaryOperation2 >
constexpr _Tp std::inner_product (_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _Tp __init, _BinaryOperation1 __binary_op1, _BinaryOperation2 __binary_op2)
 
template<typename _ForwardIterator , typename _Tp >
constexpr void std::iota (_ForwardIterator __first, _ForwardIterator __last, _Tp __value)
 
template<typename _InputIterator , typename _OutputIterator >
constexpr _OutputIterator std::partial_sum (_InputIterator __first, _InputIterator __last, _OutputIterator __result)
 
template<typename _InputIterator , typename _OutputIterator , typename _BinaryOperation >
constexpr _OutputIterator std::partial_sum (_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryOperation __binary_op)
 
template<typename _InputIterator >
constexpr iterator_traits< _InputIterator >::value_type std::reduce (_InputIterator __first, _InputIterator __last)
 
template<typename _InputIterator , typename _Tp >
constexpr _Tp std::reduce (_InputIterator __first, _InputIterator __last, _Tp __init)
 
template<typename _InputIterator , typename _Tp , typename _BinaryOperation >
constexpr _Tp std::reduce (_InputIterator __first, _InputIterator __last, _Tp __init, _BinaryOperation __binary_op)
 
template<typename _InputIterator , typename _OutputIterator , typename _Tp , typename _BinaryOperation , typename _UnaryOperation >
constexpr _OutputIterator std::transform_exclusive_scan (_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Tp __init, _BinaryOperation __binary_op, _UnaryOperation __unary_op)
 
template<typename _InputIterator , typename _OutputIterator , typename _BinaryOperation , typename _UnaryOperation >
constexpr _OutputIterator std::transform_inclusive_scan (_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryOperation __binary_op, _UnaryOperation __unary_op)
 
template<typename _InputIterator , typename _OutputIterator , typename _BinaryOperation , typename _UnaryOperation , typename _Tp >
constexpr _OutputIterator std::transform_inclusive_scan (_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryOperation __binary_op, _UnaryOperation __unary_op, _Tp __init)
 
template<typename _InputIterator , typename _Tp , typename _BinaryOperation , typename _UnaryOperation >
constexpr _Tp std::transform_reduce (_InputIterator __first, _InputIterator __last, _Tp __init, _BinaryOperation __binary_op, _UnaryOperation __unary_op)
 
template<typename _InputIterator1 , typename _InputIterator2 , typename _Tp >
constexpr _Tp std::transform_reduce (_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _Tp __init)
 
template<typename _InputIterator1 , typename _InputIterator2 , typename _Tp , typename _BinaryOperation1 , typename _BinaryOperation2 >
constexpr _Tp std::transform_reduce (_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _Tp __init, _BinaryOperation1 __binary_op1, _BinaryOperation2 __binary_op2)
 

Detailed Description

Function Documentation

◆ accumulate() [1/2]

template<typename _InputIterator , typename _Tp >
constexpr _Tp std::accumulate ( _InputIterator  __first,
_InputIterator  __last,
_Tp  __init 
)
inlineconstexpr

Accumulate values in a range.

Accumulates the values in the range [first,last) using operator+(). The initial value is init. The values are processed in order.

Parameters
__firstStart of range.
__lastEnd of range.
__initStarting value to add other values to.
Returns
The final sum.

Definition at line 134 of file stl_numeric.h.

◆ accumulate() [2/2]

template<typename _InputIterator , typename _Tp , typename _BinaryOperation >
constexpr _Tp std::accumulate ( _InputIterator  __first,
_InputIterator  __last,
_Tp  __init,
_BinaryOperation  __binary_op 
)
inlineconstexpr

Accumulate values in a range with operation.

Accumulates the values in the range [first,last) using the function object __binary_op. The initial value is __init. The values are processed in order.

Parameters
__firstStart of range.
__lastEnd of range.
__initStarting value to add other values to.
__binary_opFunction object to accumulate with.
Returns
The final sum.

Definition at line 161 of file stl_numeric.h.

◆ adjacent_difference() [1/2]

template<typename _InputIterator , typename _OutputIterator >
constexpr _OutputIterator std::adjacent_difference ( _InputIterator  __first,
_InputIterator  __last,
_OutputIterator  __result 
)
constexpr

Return differences between adjacent values.

Computes the difference between adjacent values in the range [first,last) using operator-() and writes the result to __result.

Parameters
__firstStart of input range.
__lastEnd of input range.
__resultOutput sums.
Returns
Iterator pointing just beyond the values written to result.

Definition at line 337 of file stl_numeric.h.

◆ adjacent_difference() [2/2]

template<typename _InputIterator , typename _OutputIterator , typename _BinaryOperation >
constexpr _OutputIterator std::adjacent_difference ( _InputIterator  __first,
_InputIterator  __last,
_OutputIterator  __result,
_BinaryOperation  __binary_op 
)
constexpr

Return differences between adjacent values.

Computes the difference between adjacent values in the range [__first,__last) using the function object __binary_op and writes the result to __result.

Parameters
__firstStart of input range.
__lastEnd of input range.
__resultOutput sum.
__binary_opFunction object.
Returns
Iterator pointing just beyond the values written to result.

Definition at line 380 of file stl_numeric.h.

◆ exclusive_scan() [1/2]

template<typename _InputIterator , typename _OutputIterator , typename _Tp >
constexpr _OutputIterator std::exclusive_scan ( _InputIterator  __first,
_InputIterator  __last,
_OutputIterator  __result,
_Tp  __init 
)
inlineconstexpr

Output the cumulative sum of one range to a second range.

Parameters
__firstStart of input range.
__lastEnd of input range.
__resultStart of output range.
__initInitial value.
Returns
The end of the output range.

Write the cumulative sum (aka prefix sum, aka scan) of the input range to the output range. Each element of the output range contains the running total of all earlier elements (and the initial value), using std::plus<> for summation.

This function generates an "exclusive" scan, meaning the Nth element of the output range is the sum of the first N-1 input elements, so the Nth input element is not included.

Definition at line 516 of file numeric.

References std::exclusive_scan(), and std::move().

◆ exclusive_scan() [2/2]

template<typename _InputIterator , typename _OutputIterator , typename _Tp , typename _BinaryOperation >
constexpr _OutputIterator std::exclusive_scan ( _InputIterator  __first,
_InputIterator  __last,
_OutputIterator  __result,
_Tp  __init,
_BinaryOperation  __binary_op 
)
constexpr

Output the cumulative sum of one range to a second range.

Parameters
__firstStart of input range.
__lastEnd of input range.
__resultStart of output range.
__initInitial value.
__binary_opFunction to perform summation.
Returns
The end of the output range.

Write the cumulative sum (aka prefix sum, aka scan) of the input range to the output range. Each element of the output range contains the running total of all earlier elements (and the initial value), using binary_op for summation.

This function generates an "exclusive" scan, meaning the Nth element of the output range is the sum of the first N-1 input elements, so the Nth input element is not included.

Definition at line 482 of file numeric.

References std::move().

Referenced by std::exclusive_scan().

◆ inclusive_scan() [1/3]

template<typename _InputIterator , typename _OutputIterator >
constexpr _OutputIterator std::inclusive_scan ( _InputIterator  __first,
_InputIterator  __last,
_OutputIterator  __result 
)
inlineconstexpr

Output the cumulative sum of one range to a second range.

Parameters
__firstStart of input range.
__lastEnd of input range.
__resultStart of output range.
Returns
The end of the output range.

Write the cumulative sum (aka prefix sum, aka scan) of the input range to the output range. Each element of the output range contains the running total of all earlier elements, using std::plus<> for summation.

This function generates an "inclusive" scan, meaning the Nth element of the output range is the sum of the first N input elements, so the Nth input element is included.

Definition at line 607 of file numeric.

References std::inclusive_scan().

◆ inclusive_scan() [2/3]

template<typename _InputIterator , typename _OutputIterator , typename _BinaryOperation >
constexpr _OutputIterator std::inclusive_scan ( _InputIterator  __first,
_InputIterator  __last,
_OutputIterator  __result,
_BinaryOperation  __binary_op 
)
constexpr

Output the cumulative sum of one range to a second range.

Parameters
__firstStart of input range.
__lastEnd of input range.
__resultStart of output range.
__binary_opFunction to perform summation.
Returns
The end of the output range.

Write the cumulative sum (aka prefix sum, aka scan) of the input range to the output range. Each element of the output range contains the running total of all earlier elements, using binary_op for summation.

This function generates an "inclusive" scan, meaning the Nth element of the output range is the sum of the first N input elements, so the Nth input element is included.

Definition at line 574 of file numeric.

References std::inclusive_scan(), and std::move().

◆ inclusive_scan() [3/3]

template<typename _InputIterator , typename _OutputIterator , typename _BinaryOperation , typename _Tp >
constexpr _OutputIterator std::inclusive_scan ( _InputIterator  __first,
_InputIterator  __last,
_OutputIterator  __result,
_BinaryOperation  __binary_op,
_Tp  __init 
)
constexpr

Output the cumulative sum of one range to a second range.

Parameters
__firstStart of input range.
__lastEnd of input range.
__resultStart of output range.
__binary_opFunction to perform summation.
__initInitial value.
Returns
The end of the output range.

Write the cumulative sum (aka prefix sum, aka scan) of the input range to the output range. Each element of the output range contains the running total of all earlier elements (and the initial value), using binary_op for summation.

This function generates an "inclusive" scan, meaning the Nth element of the output range is the sum of the first N input elements, so the Nth input element is included.

Definition at line 545 of file numeric.

Referenced by std::inclusive_scan().

◆ inner_product() [1/2]

template<typename _InputIterator1 , typename _InputIterator2 , typename _Tp >
constexpr _Tp std::inner_product ( _InputIterator1  __first1,
_InputIterator1  __last1,
_InputIterator2  __first2,
_Tp  __init 
)
inlineconstexpr

Compute inner product of two ranges.

Starting with an initial value of __init, multiplies successive elements from the two ranges and adds each product into the accumulated value using operator+(). The values in the ranges are processed in order.

Parameters
__first1Start of range 1.
__last1End of range 1.
__first2Start of range 2.
__initStarting value to add other values to.
Returns
The final inner product.

Definition at line 190 of file stl_numeric.h.

◆ inner_product() [2/2]

template<typename _InputIterator1 , typename _InputIterator2 , typename _Tp , typename _BinaryOperation1 , typename _BinaryOperation2 >
constexpr _Tp std::inner_product ( _InputIterator1  __first1,
_InputIterator1  __last1,
_InputIterator2  __first2,
_Tp  __init,
_BinaryOperation1  __binary_op1,
_BinaryOperation2  __binary_op2 
)
inlineconstexpr

Compute inner product of two ranges.

Starting with an initial value of __init, applies __binary_op2 to successive elements from the two ranges and accumulates each result into the accumulated value using __binary_op1. The values in the ranges are processed in order.

Parameters
__first1Start of range 1.
__last1End of range 1.
__first2Start of range 2.
__initStarting value to add other values to.
__binary_op1Function object to accumulate with.
__binary_op2Function object to apply to pairs of input values.
Returns
The final inner product.

Definition at line 223 of file stl_numeric.h.

◆ iota()

template<typename _ForwardIterator , typename _Tp >
constexpr void std::iota ( _ForwardIterator  __first,
_ForwardIterator  __last,
_Tp  __value 
)
constexpr

Create a range of sequentially increasing values.

For each element in the range [first,last) assigns value and increments value as if by ++value.

Parameters
__firstStart of range.
__lastEnd of range.
__valueStarting value.
Returns
Nothing.

Definition at line 88 of file stl_numeric.h.

◆ partial_sum() [1/2]

template<typename _InputIterator , typename _OutputIterator >
constexpr _OutputIterator std::partial_sum ( _InputIterator  __first,
_InputIterator  __last,
_OutputIterator  __result 
)
constexpr

Return list of partial sums.

Accumulates the values in the range [first,last) using the + operator. As each successive input value is added into the total, that partial sum is written to __result. Therefore, the first value in __result is the first value of the input, the second value in __result is the sum of the first and second input values, and so on.

Parameters
__firstStart of input range.
__lastEnd of input range.
__resultOutput sum.
Returns
Iterator pointing just beyond the values written to __result.

Definition at line 256 of file stl_numeric.h.

◆ partial_sum() [2/2]

template<typename _InputIterator , typename _OutputIterator , typename _BinaryOperation >
constexpr _OutputIterator std::partial_sum ( _InputIterator  __first,
_InputIterator  __last,
_OutputIterator  __result,
_BinaryOperation  __binary_op 
)
constexpr

Return list of partial sums.

Accumulates the values in the range [first,last) using __binary_op. As each successive input value is added into the total, that partial sum is written to __result. Therefore, the first value in __result is the first value of the input, the second value in __result is the sum of the first and second input values, and so on.

Parameters
__firstStart of input range.
__lastEnd of input range.
__resultOutput sum.
__binary_opFunction object.
Returns
Iterator pointing just beyond the values written to __result.

Definition at line 298 of file stl_numeric.h.

◆ reduce() [1/3]

template<typename _InputIterator >
constexpr iterator_traits< _InputIterator >::value_type std::reduce ( _InputIterator  __first,
_InputIterator  __last 
)
inlineconstexpr

Calculate reduction of values in a range.

Parameters
__firstStart of range.
__lastEnd of range.
Returns
The final sum.

Reduce the values in the range [first,last) using addition, with an initial value of T{}, where T is the iterator's value type. Equivalent to calling std::reduce(first, last, T{}, std::plus<>()).

Definition at line 342 of file numeric.

References std::reduce().

◆ reduce() [2/3]

template<typename _InputIterator , typename _Tp >
constexpr _Tp std::reduce ( _InputIterator  __first,
_InputIterator  __last,
_Tp  __init 
)
inlineconstexpr

Calculate reduction of values in a range.

Parameters
__firstStart of range.
__lastEnd of range.
__initStarting value to add other values to.
Returns
The final sum.

Reduce the values in the range [first,last) using addition. Equivalent to calling std::reduce(first, last, init, std::plus<>()).

Definition at line 325 of file numeric.

References std::move(), and std::reduce().

◆ reduce() [3/3]

template<typename _InputIterator , typename _Tp , typename _BinaryOperation >
constexpr _Tp std::reduce ( _InputIterator  __first,
_InputIterator  __last,
_Tp  __init,
_BinaryOperation  __binary_op 
)
constexpr

Calculate reduction of values in a range.

Parameters
__firstStart of range.
__lastEnd of range.
__initStarting value to add other values to.
__binary_opA binary function object.
Returns
The final sum.

Reduce the values in the range [first,last) using a binary operation. The initial value is init. The values are not necessarily processed in order.

This algorithm is similar to std::accumulate but is not required to perform the operations in order from first to last. For operations that are commutative and associative the result will be the same as for std::accumulate, but for other operations (such as floating point arithmetic) the result can be different.

Definition at line 287 of file numeric.

Referenced by std::reduce().

◆ transform_exclusive_scan()

template<typename _InputIterator , typename _OutputIterator , typename _Tp , typename _BinaryOperation , typename _UnaryOperation >
constexpr _OutputIterator std::transform_exclusive_scan ( _InputIterator  __first,
_InputIterator  __last,
_OutputIterator  __result,
_Tp  __init,
_BinaryOperation  __binary_op,
_UnaryOperation  __unary_op 
)
constexpr

Output the cumulative sum of one range to a second range.

Parameters
__firstStart of input range.
__lastEnd of input range.
__resultStart of output range.
__initInitial value.
__binary_opFunction to perform summation.
__unary_opFunction to transform elements of the input range.
Returns
The end of the output range.

Write the cumulative sum (aka prefix sum, aka scan) of the input range to the output range. Each element of the output range contains the running total of all earlier elements (and the initial value), using __unary_op to transform the input elements and using __binary_op for summation.

This function generates an "exclusive" scan, meaning the Nth element of the output range is the sum of the first N-1 input elements, so the Nth input element is not included.

Definition at line 635 of file numeric.

References std::move().

◆ transform_inclusive_scan() [1/2]

template<typename _InputIterator , typename _OutputIterator , typename _BinaryOperation , typename _UnaryOperation >
constexpr _OutputIterator std::transform_inclusive_scan ( _InputIterator  __first,
_InputIterator  __last,
_OutputIterator  __result,
_BinaryOperation  __binary_op,
_UnaryOperation  __unary_op 
)
constexpr

Output the cumulative sum of one range to a second range.

Parameters
__firstStart of input range.
__lastEnd of input range.
__resultStart of output range.
__binary_opFunction to perform summation.
__unary_opFunction to transform elements of the input range.
Returns
The end of the output range.

Write the cumulative sum (aka prefix sum, aka scan) of the input range to the output range. Each element of the output range contains the running total of all earlier elements, using __unary_op to transform the input elements and using __binary_op for summation.

This function generates an "inclusive" scan, meaning the Nth element of the output range is the sum of the first N input elements, so the Nth input element is included.

Definition at line 708 of file numeric.

References std::move(), and std::transform_inclusive_scan().

◆ transform_inclusive_scan() [2/2]

template<typename _InputIterator , typename _OutputIterator , typename _BinaryOperation , typename _UnaryOperation , typename _Tp >
constexpr _OutputIterator std::transform_inclusive_scan ( _InputIterator  __first,
_InputIterator  __last,
_OutputIterator  __result,
_BinaryOperation  __binary_op,
_UnaryOperation  __unary_op,
_Tp  __init 
)
constexpr

Output the cumulative sum of one range to a second range.

Parameters
__firstStart of input range.
__lastEnd of input range.
__resultStart of output range.
__binary_opFunction to perform summation.
__unary_opFunction to transform elements of the input range.
__initInitial value.
Returns
The end of the output range.

Write the cumulative sum (aka prefix sum, aka scan) of the input range to the output range. Each element of the output range contains the running total of all earlier elements (and the initial value), using __unary_op to transform the input elements and using __binary_op for summation.

This function generates an "inclusive" scan, meaning the Nth element of the output range is the sum of the first N input elements, so the Nth input element is included.

Definition at line 674 of file numeric.

Referenced by std::transform_inclusive_scan().

◆ transform_reduce() [1/3]

template<typename _InputIterator , typename _Tp , typename _BinaryOperation , typename _UnaryOperation >
constexpr _Tp std::transform_reduce ( _InputIterator  __first,
_InputIterator  __last,
_Tp  __init,
_BinaryOperation  __binary_op,
_UnaryOperation  __unary_op 
)
constexpr

Transform the elements of a range and reduce.

Parameters
__firstStart of range.
__lastEnd of range.
__initStarting value to add other values to.
__binary_opThe function used to perform reduction.
__unary_opThe function used to transform values from the range.
Returns
The final sum.

Call unary_op(first[n]) for each n in [0,last-first) and then use binary_op to reduce the values returned by unary_op to a single value of type T.

Definition at line 439 of file numeric.

◆ transform_reduce() [2/3]

template<typename _InputIterator1 , typename _InputIterator2 , typename _Tp >
constexpr _Tp std::transform_reduce ( _InputIterator1  __first1,
_InputIterator1  __last1,
_InputIterator2  __first2,
_Tp  __init 
)
inlineconstexpr

Combine elements from two ranges and reduce.

Parameters
__first1Start of first range.
__last1End of first range.
__first2Start of second range.
__initStarting value to add other values to.
Returns
The final sum.

Call first1[n]*first2[n] for each n in [0,last1-first1) and then use addition to sum those products to a single value of type T.

The range beginning at first2 must contain at least last1-first1 elements.

Definition at line 413 of file numeric.

References std::move(), and std::transform_reduce().

◆ transform_reduce() [3/3]

template<typename _InputIterator1 , typename _InputIterator2 , typename _Tp , typename _BinaryOperation1 , typename _BinaryOperation2 >
constexpr _Tp std::transform_reduce ( _InputIterator1  __first1,
_InputIterator1  __last1,
_InputIterator2  __first2,
_Tp  __init,
_BinaryOperation1  __binary_op1,
_BinaryOperation2  __binary_op2 
)
constexpr

Combine elements from two ranges and reduce.

Parameters
__first1Start of first range.
__last1End of first range.
__first2Start of second range.
__initStarting value to add other values to.
__binary_op1The function used to perform reduction.
__binary_op2The function used to combine values from the ranges.
Returns
The final sum.

Call binary_op2(first1[n],first2[n]) for each n in [0,last1-first1) and then use binary_op1 to reduce the values returned by binary_op2 to a single value of type T.

The range beginning at first2 must contain at least last1-first1 elements.

Definition at line 370 of file numeric.

Referenced by std::transform_reduce().