transform function template — Copies one or two ranges after applying an operator to each element
template<typename InIter, typename OutIter, typename UnaryOperation> OutIter transform(InIter first, InIter last, OutIter result, UnaryOperation unop); template<typename InIter1, typename InIter2, typename OutIter, typename BinaryOperation> OutIter transform(InIter1 first1, InIter1 last1, InIter2 first2, OutIter result, BinaryOperation binop);
The transform
function
template assigns a new value to each element in the range that
starts at result
. In the first
case, the new value is unop(*iter)
, in which iter
is an iterator over [first
, last
).
In the second case, the new value is binop(*iter1
, *iter2)
, in which iter1
ranges over [first1
, last1
) and iter2
iterates over the range that starts
at first2
. The second input range
must be at least as long as the first.
The return value is one past the end of the result range. The result range can be the same as any of the input ranges.
The first form of transform
assigns *(result
+ n
) =
unop(*(first
+ n
)) for all n
in [0, last
- first
).
The second form assigns *(result
+ n
) =
binop(*(first1
+ n
), *(first2
+ n
)) for all n
in [0, last1
- first1
).
Complexity is linear: unop or
binop is called exactly n
times, in which n
= last
- first
for a unary operator or last1
- first1
for a binary operator.