[numeric.ops.overview] # 26 Algorithms library [[algorithms]](./#algorithms) ## 26.9 Header synopsis [numeric.ops.overview] [🔗](#header:%3cnumeric%3e) // mostly freestandingnamespace std {// [[accumulate]](accumulate "26.10.3 Accumulate"), accumulatetemplateconstexpr T accumulate(InputIterator first, InputIterator last, T init); templateconstexpr T accumulate(InputIterator first, InputIterator last, T init, BinaryOperation binary_op); // [[reduce]](reduce "26.10.4 Reduce"), reducetemplateconstexpr typename iterator_traits::value_type reduce(InputIterator first, InputIterator last); templateconstexpr T reduce(InputIterator first, InputIterator last, T init); templateconstexpr T reduce(InputIterator first, InputIterator last, T init, BinaryOperation binary_op); templatetypename iterator_traits::value_type reduce(ExecutionPolicy&& exec, // freestanding-deleted, see [[algorithms.parallel.overloads]](algorithms.parallel.overloads "26.3.5 Parallel algorithm overloads") ForwardIterator first, ForwardIterator last); template T reduce(ExecutionPolicy&& exec, // freestanding-deleted, see [[algorithms.parallel.overloads]](algorithms.parallel.overloads "26.3.5 Parallel algorithm overloads") ForwardIterator first, ForwardIterator last, T init); template T reduce(ExecutionPolicy&& exec, // freestanding-deleted, see [[algorithms.parallel.overloads]](algorithms.parallel.overloads "26.3.5 Parallel algorithm overloads") ForwardIterator first, ForwardIterator last, T init, BinaryOperation binary_op); // [[inner.product]](inner.product "26.10.5 Inner product"), inner producttemplateconstexpr T inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, T init); templateconstexpr T inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, T init, BinaryOperation1 binary_op1, BinaryOperation2 binary_op2); // [[transform.reduce]](transform.reduce "26.10.6 Transform reduce"), transform reducetemplateconstexpr T transform_reduce(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, T init); templateconstexpr T transform_reduce(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, T init, BinaryOperation1 binary_op1, BinaryOperation2 binary_op2); templateconstexpr T transform_reduce(InputIterator first, InputIterator last, T init, BinaryOperation binary_op, UnaryOperation unary_op); template T transform_reduce(ExecutionPolicy&& exec, // freestanding-deleted, see [[algorithms.parallel.overloads]](algorithms.parallel.overloads "26.3.5 Parallel algorithm overloads") ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, T init); template T transform_reduce(ExecutionPolicy&& exec, // freestanding-deleted, see [[algorithms.parallel.overloads]](algorithms.parallel.overloads "26.3.5 Parallel algorithm overloads") ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, T init, BinaryOperation1 binary_op1, BinaryOperation2 binary_op2); template T transform_reduce(ExecutionPolicy&& exec, // freestanding-deleted, see [[algorithms.parallel.overloads]](algorithms.parallel.overloads "26.3.5 Parallel algorithm overloads") ForwardIterator first, ForwardIterator last, T init, BinaryOperation binary_op, UnaryOperation unary_op); // [[partial.sum]](partial.sum "26.10.7 Partial sum"), partial sumtemplateconstexpr OutputIterator partial_sum(InputIterator first, InputIterator last, OutputIterator result); templateconstexpr OutputIterator partial_sum(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op); // [[exclusive.scan]](exclusive.scan "26.10.8 Exclusive scan"), exclusive scantemplateconstexpr OutputIterator exclusive_scan(InputIterator first, InputIterator last, OutputIterator result, T init); templateconstexpr OutputIterator exclusive_scan(InputIterator first, InputIterator last, OutputIterator result, T init, BinaryOperation binary_op); template ForwardIterator2 exclusive_scan(ExecutionPolicy&& exec, // freestanding-deleted, see [[algorithms.parallel.overloads]](algorithms.parallel.overloads "26.3.5 Parallel algorithm overloads") ForwardIterator1 first, ForwardIterator1 last, ForwardIterator2 result, T init); template ForwardIterator2 exclusive_scan(ExecutionPolicy&& exec, // freestanding-deleted, see [[algorithms.parallel.overloads]](algorithms.parallel.overloads "26.3.5 Parallel algorithm overloads") ForwardIterator1 first, ForwardIterator1 last, ForwardIterator2 result, T init, BinaryOperation binary_op); // [[inclusive.scan]](inclusive.scan "26.10.9 Inclusive scan"), inclusive scantemplateconstexpr OutputIterator inclusive_scan(InputIterator first, InputIterator last, OutputIterator result); templateconstexpr OutputIterator inclusive_scan(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op); templateconstexpr OutputIterator inclusive_scan(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op, T init); template ForwardIterator2 inclusive_scan(ExecutionPolicy&& exec, // freestanding-deleted, see [[algorithms.parallel.overloads]](algorithms.parallel.overloads "26.3.5 Parallel algorithm overloads") ForwardIterator1 first, ForwardIterator1 last, ForwardIterator2 result); template ForwardIterator2 inclusive_scan(ExecutionPolicy&& exec, // freestanding-deleted, see [[algorithms.parallel.overloads]](algorithms.parallel.overloads "26.3.5 Parallel algorithm overloads") ForwardIterator1 first, ForwardIterator1 last, ForwardIterator2 result, BinaryOperation binary_op); template ForwardIterator2 inclusive_scan(ExecutionPolicy&& exec, // freestanding-deleted, see [[algorithms.parallel.overloads]](algorithms.parallel.overloads "26.3.5 Parallel algorithm overloads") ForwardIterator1 first, ForwardIterator1 last, ForwardIterator2 result, BinaryOperation binary_op, T init); // [[transform.exclusive.scan]](transform.exclusive.scan "26.10.10 Transform exclusive scan"), transform exclusive scantemplateconstexpr OutputIterator transform_exclusive_scan(InputIterator first, InputIterator last, OutputIterator result, T init, BinaryOperation binary_op, UnaryOperation unary_op); template ForwardIterator2 transform_exclusive_scan(ExecutionPolicy&& exec, // freestanding-deleted, see [[algorithms.parallel.overloads]](algorithms.parallel.overloads "26.3.5 Parallel algorithm overloads") ForwardIterator1 first, ForwardIterator1 last, ForwardIterator2 result, T init, BinaryOperation binary_op, UnaryOperation unary_op); // [[transform.inclusive.scan]](transform.inclusive.scan "26.10.11 Transform inclusive scan"), transform inclusive scantemplateconstexpr OutputIterator transform_inclusive_scan(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op, UnaryOperation unary_op); templateconstexpr OutputIterator transform_inclusive_scan(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op, UnaryOperation unary_op, T init); template ForwardIterator2 transform_inclusive_scan(ExecutionPolicy&& exec, // freestanding-deleted, see [[algorithms.parallel.overloads]](algorithms.parallel.overloads "26.3.5 Parallel algorithm overloads") ForwardIterator1 first, ForwardIterator1 last, ForwardIterator2 result, BinaryOperation binary_op, UnaryOperation unary_op); template ForwardIterator2 transform_inclusive_scan(ExecutionPolicy&& exec, // freestanding-deleted, see [[algorithms.parallel.overloads]](algorithms.parallel.overloads "26.3.5 Parallel algorithm overloads") ForwardIterator1 first, ForwardIterator1 last, ForwardIterator2 result, BinaryOperation binary_op, UnaryOperation unary_op, T init); // [[adjacent.difference]](adjacent.difference "26.10.12 Adjacent difference"), adjacent differencetemplateconstexpr OutputIterator adjacent_difference(InputIterator first, InputIterator last, OutputIterator result); templateconstexpr OutputIterator adjacent_difference(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op); template ForwardIterator2 adjacent_difference(ExecutionPolicy&& exec, // freestanding-deleted, see [[algorithms.parallel.overloads]](algorithms.parallel.overloads "26.3.5 Parallel algorithm overloads") ForwardIterator1 first, ForwardIterator1 last, ForwardIterator2 result); template ForwardIterator2 adjacent_difference(ExecutionPolicy&& exec, // freestanding-deleted, see [[algorithms.parallel.overloads]](algorithms.parallel.overloads "26.3.5 Parallel algorithm overloads") ForwardIterator1 first, ForwardIterator1 last, ForwardIterator2 result, BinaryOperation binary_op); // [[numeric.iota]](numeric.iota "26.10.13 Iota"), iotatemplateconstexpr void iota(ForwardIterator first, ForwardIterator last, T value); namespace ranges {templateusing [iota_result](#lib:iota_result "26.9 Header synopsis [numeric.ops.overview]") = out_value_result; template<[input_or_output_iterator](iterator.concept.iterator#concept:input_or_output_iterator "24.3.4.6 Concept input_­or_­output_­iterator [iterator.concept.iterator]") O, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]") S, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4 Concept weakly_­incrementable [iterator.concept.winc]") T>requires [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3 Concept indirectly_­writable [iterator.concept.writable]")constexpr iota_result iota(O first, S last, T value); template<[weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4 Concept weakly_­incrementable [iterator.concept.winc]") T, [output_range](range.refinements#concept:output_range "25.4.6 Other range refinements [range.refinements]") R>constexpr iota_result, T> iota(R&& r, T value); }// [[numeric.ops.gcd]](numeric.ops.gcd "26.10.14 Greatest common divisor"), greatest common divisortemplateconstexpr common_type_t gcd(M m, N n); // [[numeric.ops.lcm]](numeric.ops.lcm "26.10.15 Least common multiple"), least common multipletemplateconstexpr common_type_t lcm(M m, N n); // [[numeric.ops.midpoint]](numeric.ops.midpoint "26.10.16 Midpoint"), midpointtemplateconstexpr T midpoint(T a, T b) noexcept; templateconstexpr T* midpoint(T* a, T* b); // [[numeric.sat]](numeric.sat "26.10.17 Saturation arithmetic"), saturation arithmetictemplateconstexpr T add_sat(T x, T y) noexcept; templateconstexpr T sub_sat(T x, T y) noexcept; templateconstexpr T mul_sat(T x, T y) noexcept; templateconstexpr T div_sat(T x, T y) noexcept; templateconstexpr T saturate_cast(U x) noexcept;}