Generalized Numeric operations
Algorithms
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
| ) |  |

inline constexpr

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

  __first | Start of range.
  __last | End of range.
  __init | Starting 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
| ) |  |

inline constexpr

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

  __first | Start of range.
  __last | End of range.
  __init | Starting value to add other values to.
  __binary_op | Function 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

  __first | Start of input range.
  __last | End of input range.
  __result | Output sums.

Returns
  Iterator pointing just beyond the values written to result.

_GLIBCXX_RESOLVE_LIB_DEFECTS DR 539. partial_sum and adjacent_difference should mention requirements

Definition at line 338 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

  __first | Start of input range.
  __last | End of input range.
  __result | Output sum.
  __binary_op | Function object.

Returns
  Iterator pointing just beyond the values written to result.

_GLIBCXX_RESOLVE_LIB_DEFECTS DR 539. partial_sum and adjacent_difference should mention requirements

Definition at line 382 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
| ) |  |

inline constexpr

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

Parameters

  __first | Start of input range.
  __last | End of input range.
  __result | Start of output range.
  __init | Initial 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.

## 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

  __first | Start of input range.
  __last | End of input range.
  __result | Start of output range.
  __init | Initial value.
  __binary_op | Function 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.

## inclusive_scan() [1/3]

template<typename _InputIterator , typename _OutputIterator >

constexpr _OutputIterator std::inclusive_scan | ( | _InputIterator | __first,
|  | _InputIterator | __last,
|  | _OutputIterator | __result
| ) |  |

inline constexpr

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

Parameters

  __first | Start of input range.
  __last | End of input range.
  __result | Start 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.

## 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

  __first | Start of input range.
  __last | End of input range.
  __result | Start of output range.
  __binary_op | Function 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.

## 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

  __first | Start of input range.
  __last | End of input range.
  __result | Start of output range.
  __binary_op | Function to perform summation.
  __init | Initial 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.

## inner_product() [1/2]

template<typename _InputIterator1 , typename _InputIterator2 , typename _Tp >

constexpr _Tp std::inner_product | ( | _InputIterator1 | __first1,
|  | _InputIterator1 | __last1,
|  | _InputIterator2 | __first2,
|  | _Tp | __init
| ) |  |

inline constexpr

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

  __first1 | Start of range 1.
  __last1 | End of range 1.
  __first2 | Start of range 2.
  __init | Starting 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
| ) |  |

inline constexpr

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

  __first1 | Start of range 1.
  __last1 | End of range 1.
  __first2 | Start of range 2.
  __init | Starting value to add other values to.
  __binary_op1 | Function object to accumulate with.
  __binary_op2 | Function 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

  __first | Start of range.
  __last | End of range.
  __value | Starting 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

  __first | Start of input range.
  __last | End of input range.
  __result | Output 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

  __first | Start of input range.
  __last | End of input range.
  __result | Output sum.
  __binary_op | Function 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
| ) |  |

inline constexpr

Calculate reduction of values in a range.

Parameters

  __first | Start of range.
  __last | End 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.

## reduce() [2/3]

template<typename _InputIterator , typename _Tp >

constexpr _Tp std::reduce | ( | _InputIterator | __first,
|  | _InputIterator | __last,
|  | _Tp | __init
| ) |  |

inline constexpr

Calculate reduction of values in a range.

Parameters

  __first | Start of range.
  __last | End of range.
  __init | Starting 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.

## 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

  __first | Start of range.
  __last | End of range.
  __init | Starting value to add other values to.
  __binary_op | A 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.

## 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

  __first | Start of input range.
  __last | End of input range.
  __result | Start of output range.
  __init | Initial value.
  __binary_op | Function to perform summation.
  __unary_op | Function 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.

## 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

  __first | Start of input range.
  __last | End of input range.
  __result | Start of output range.
  __binary_op | Function to perform summation.
  __unary_op | Function 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.

## 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

  __first | Start of input range.
  __last | End of input range.
  __result | Start of output range.
  __binary_op | Function to perform summation.
  __unary_op | Function to transform elements of the input range.
  __init | Initial 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.

## 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

  __first | Start of range.
  __last | End of range.
  __init | Starting value to add other values to.
  __binary_op | The function used to perform reduction.
  __unary_op | The 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
| ) |  |

inline constexpr

Combine elements from two ranges and reduce.

Parameters

  __first1 | Start of first range.
  __last1 | End of first range.
  __first2 | Start of second range.
  __init | Starting 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.

## 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

  __first1 | Start of first range.
  __last1 | End of first range.
  __first2 | Start of second range.
  __init | Starting value to add other values to.
  __binary_op1 | The function used to perform reduction.
  __binary_op2 | The 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.