Standard C++ Library Class Reference
InputIterator2 first2,
OutputIterator result,
BinaryOperation binary_op);
Description
The transform algorithm has two forms. The first form applies unary operation op to each
element of the range [first, last), and sends the result to the output iterator result. For example,
this version of transform, could be used to square each element in a vector. If the output iterator
(result) is the same as the input iterator used to traverse the range, transform, performs its
transformation inplace.
The second form of transform applies a binary operation, binary_op, to corresponding elements
in the range [first1, last1) and the range that begins at first2, and sends the result to result. For
example, transform can be used to add corresponding elements in two sequences, and store the
set of sums in a third. The algorithm assumes, but does not check, that the second sequence has
at least as many elements as the first sequence. Note that the output iterator result can be a third
sequence, or either of the two input sequences.
Formally, transform assigns through every iterator i in the range [result, result + (last1 - first1))
a new corresponding value equal to:
op(*(first1 + (i - result))
or
binary_op(*(first1 + (i - result), *(first2 + (i - result)))
transform returns result + (last1 - first1). op and binary_op must not have any side effects.
result may be equal to first in case of unary transform, or to first1 or first2 in case of binary
transform.
Complexity
Exactly last1 - first1 applications of op or binary_op are performed.
Example
//
// trnsform.cpp
//
#include <functional>
#include <deque>
#include <algorithm>
#include <iostream.h>
#include <iomanip.h>
int main()