# 11 Algorithms library [algorithms]

## 11.4 Mutating sequence operations [alg.modifying.operations]

### 11.4.4 Transform [alg.transform]

``` template <InputIterator I, Sentinel<I> S, WeaklyIncrementable O, CopyConstructible F, class Proj = identity> requires Writable<O, indirect_result_of_t<F&(projected<I, Proj>)>> tagged_pair<tag::in(I), tag::out(O)> transform(I first, S last, O result, F op, Proj proj = Proj{}); template <InputRange Rng, WeaklyIncrementable O, CopyConstructible F, class Proj = identity> requires Writable<O, indirect_result_of_t<F&( projected<iterator_t<R>, Proj>)>> tagged_pair<tag::in(safe_iterator_t<Rng>), tag::out(O)> transform(Rng&& rng, O result, F op, Proj proj = Proj{}); template <InputIterator I1, Sentinel<I1> S1, InputIterator I2, Sentinel<I2> S2, WeaklyIncrementable O, CopyConstructible F, class Proj1 = identity, class Proj2 = identity> requires Writable<O, indirect_result_of_t<F&(projected<I1, Proj1>, projected<I2, Proj2>)>> tagged_tuple<tag::in1(I1), tag::in2(I2), tag::out(O)> transform(I1 first1, S1 last1, I2 first2, S2 last2, O result, F binary_op, Proj1 proj1 = Proj1{}, Proj2 proj2 = Proj2{}); template <InputRange Rng1, InputRange Rng2, WeaklyIncrementable O, CopyConstructible F, class Proj1 = identity, class Proj2 = identity> requires Writable<O, indirect_result_of_t<F&( projected<iterator_t<Rng1>, Proj1>, projected<iterator_t<Rng2>, Proj2>)>> tagged_tuple<tag::in1(safe_iterator_t<Rng1>), tag::in2(safe_iterator_t<Rng2>), tag::out(O)> transform(Rng1&& rng1, Rng2&& rng2, O result, F binary_op, Proj1 proj1 = Proj1{}, Proj2 proj2 = Proj2{}); ```

Let N be (last1 - first1) for unary transforms, or min(last1 - first1, last2 - first2) for binary transforms.

Effects: Assigns through every iterator i in the range [result,result + N) a new corresponding value equal to invoke(op, invoke(proj, *(first1 + (i - result)))) or invoke(binary_op, invoke(proj1, *(first1 + (i - result))), invoke(proj2, *(first2 + (i - result)))).

Requires: op and binary_op shall not invalidate iterators or subranges, or modify elements in the ranges [first1,first1 + N], [first2,first2 + N], and [result,result + N].7

Returns: {first1 + N, result + N} or make_tagged_tuple<tag::in1, tag::in2, tag::out>(first1 + N, first2 + N, result + N).

Complexity: Exactly N applications of op or binary_op and the corresponding projection(s).

Remarks: result may be equal to first1 in case of unary transform, or to first1 or first2 in case of binary transform.

The use of fully closed ranges is intentional.