[transform.exclusive.scan]

# 26 Algorithms library [[algorithms]](./#algorithms)

## 26.10 Generalized numeric operations [[numeric.ops]](numeric.ops#transform.exclusive.scan)

### 26.10.10 Transform exclusive scan [transform.exclusive.scan]

[ð](#lib:transform_exclusive_scan)

`template<class InputIterator, class OutputIterator, class T,
         class BinaryOperation, class UnaryOperation>
  constexpr OutputIterator
    transform_exclusive_scan(InputIterator first, InputIterator last,
                             OutputIterator result, T init,
                             BinaryOperation binary_op, UnaryOperation unary_op);
template<class ExecutionPolicy,
         class ForwardIterator1, class ForwardIterator2, class T,
         class BinaryOperation, class UnaryOperation>
  ForwardIterator2
    transform_exclusive_scan(ExecutionPolicy&& exec,
                             ForwardIterator1 first, ForwardIterator1 last,
                             ForwardIterator2 result, T init,
                             BinaryOperation binary_op, UnaryOperation unary_op);
`

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L12953)

*Mandates*: All of 

- [(1.1)](#1.1)

binary_op(init, init),

- [(1.2)](#1.2)

binary_op(init, unary_op(*first)), and

- [(1.3)](#1.3)

binary_op(unary_op(*first), unary_op(*first))

are convertible to T[.](#1.sentence-1)

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L12963)

*Preconditions*: 

- [(2.1)](#2.1)

  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[.](#2.1.sentence-1)

- [(2.2)](#2.2)

  Neither unary_op nor binary_op invalidates iterators or subranges, nor modifies elements in
 the ranges [first, last] or [result, result + (last - first)][.](#2.2.sentence-1)

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L12974)

*Effects*: For each integer K in [0, last - first)
assigns through result + K the value of:*GENERALIZED_NONCOMMUTATIVE_SUM*( binary_op, init,
 unary_op(*(first + 0)), unary_op(*(first + 1)), …, unary_op(*(first + K - 1)))

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L12984)

*Returns*: The end of the resulting range beginning at result[.](#4.sentence-1)

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L12988)

*Complexity*: O(last - first) applications each
of unary_op and binary_op[.](#5.sentence-1)

[6](#6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L12993)

*Remarks*: result may be equal to first[.](#6.sentence-1)

[7](#7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L12997)

[*Note [1](#note-1)*:

The difference between transform_exclusive_scan andtransform_inclusive_scan is that transform_exclusive_scan excludes the ith input element from the ith sum[.](#7.sentence-1)

If binary_op is not mathematically associative,
the behavior of transform_exclusive_scan can be nondeterministic[.](#7.sentence-2)

transform_exclusive_scan does not apply unary_op to init[.](#7.sentence-3)

â *end note*]
