[partial.sum] # 26 Algorithms library [[algorithms]](./#algorithms) ## 26.10 Generalized numeric operations [[numeric.ops]](numeric.ops#partial.sum) ### 26.10.7 Partial sum [partial.sum] [🔗](#lib:partial_sum) `template constexpr OutputIterator partial_sum(InputIterator first, InputIterator last, OutputIterator result); template constexpr OutputIterator partial_sum(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op); ` [1](#1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L12657) *Mandates*: InputIterator's value type is constructible from *first[.](#1.sentence-1) The result of the expression std​::​move(acc) + *i or binary_op(std​::​move(acc), *i) is implicitly convertible to InputIterator's value type[.](#1.sentence-2) acc is writable ([[iterator.requirements.general]](iterator.requirements.general "24.3.1 General")) to result[.](#1.sentence-3) [2](#2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L12665) *Preconditions*: In the ranges [first, last] and [result, result + (last - first)]binary_op neither modifies elements nor invalidates iterators or subranges[.](#2.sentence-1)[208](#footnote-208 "The use of fully closed ranges is intentional.") [3](#3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L12674) *Effects*: For a non-empty range, the function creates an accumulator acc whose type is InputIterator's value type, initializes it with *first, and assigns the result to *result[.](#3.sentence-1) For every iterator i in [first + 1, last) in order,acc is then modified byacc = std​::​move(acc) + *i or acc = binary_op(std​::​move(acc), *i) and the result is assigned to *(result + (i - first))[.](#3.sentence-2) [4](#4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L12686) *Returns*: result + (last - first)[.](#4.sentence-1) [5](#5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L12690) *Complexity*: Exactly (last - first) - 1 applications of the binary operation[.](#5.sentence-1) [6](#6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L12694) *Remarks*: result may be equal to first[.](#6.sentence-1) [208)](#footnote-208)[208)](#footnoteref-208) The use of fully closed ranges is intentional[.](#footnote-208.sentence-1)