[transform.inclusive.scan] # 26 Algorithms library [[algorithms]](./#algorithms) ## 26.10 Generalized numeric operations [[numeric.ops]](numeric.ops#transform.inclusive.scan) ### 26.10.11 Transform inclusive scan [transform.inclusive.scan] [🔗](#lib:transform_inclusive_scan) `template constexpr OutputIterator transform_inclusive_scan(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op, UnaryOperation unary_op); template ForwardIterator2 transform_inclusive_scan(ExecutionPolicy&& exec, ForwardIterator1 first, ForwardIterator1 last, ForwardIterator2 result, BinaryOperation binary_op, UnaryOperation unary_op); template constexpr 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, ForwardIterator1 first, ForwardIterator1 last, ForwardIterator2 result, BinaryOperation binary_op, UnaryOperation unary_op, T init); ` [1](#1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13046) Let U be the value type of decltype(first)[.](#1.sentence-1) [2](#2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13049) *Mandates*: If init is provided, all of - [(2.1)](#2.1) binary_op(init, init), - [(2.2)](#2.2) binary_op(init, unary_op(*first)), and - [(2.3)](#2.3) binary_op(unary_op(*first), unary_op(*first)) are convertible to T; otherwise, binary_op(unary_op(*first), unary_op(*first)) is convertible to U[.](#2.sentence-1) [3](#3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13061) *Preconditions*: - [(3.1)](#3.1) If init is provided, T meets the [*Cpp17MoveConstructible*](utility.arg.requirements#:Cpp17MoveConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") (Table [31](utility.arg.requirements#tab:cpp17.moveconstructible "Table 31: Cpp17MoveConstructible requirements")) requirements; otherwise, U meets the [*Cpp17MoveConstructible*](utility.arg.requirements#:Cpp17MoveConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") requirements[.](#3.1.sentence-1) - [(3.2)](#3.2) Neither unary_op nor binary_op invalidates iterators or subranges, nor modifies elements in the ranges [first, last] or [result, result + (last - first)][.](#3.2.sentence-1) [4](#4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13075) *Effects*: For each integer K in [0, last - first) assigns through result + K the value of - [(4.1)](#4.1) *GENERALIZED_NONCOMMUTATIVE_SUM*( binary_op, init, unary_op(*(first + 0)), unary_op(*(first + 1)), …, unary_op(*(first + K))) if init is provided, or - [(4.2)](#4.2) *GENERALIZED_NONCOMMUTATIVE_SUM*( binary_op, unary_op(*(first + 0)), unary_op(*(first + 1)), …, unary_op(*(first + K))) otherwise[.](#4.2.sentence-2) [5](#5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13088) *Returns*: The end of the resulting range beginning at result[.](#5.sentence-1) [6](#6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13092) *Complexity*: O(last - first) applications each of unary_op and binary_op[.](#6.sentence-1) [7](#7) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13097) *Remarks*: result may be equal to first[.](#7.sentence-1) [8](#8) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13101) [*Note [1](#note-1)*: The difference between transform_exclusive_scan andtransform_inclusive_scan is that transform_inclusive_scan includes the ith input element in the ith sum[.](#8.sentence-1) If binary_op is not mathematically associative, the behavior of transform_inclusive_scan can be nondeterministic[.](#8.sentence-2) transform_inclusive_scan does not apply unary_op to init[.](#8.sentence-3) — *end note*]