Syntax:
#include <algorithm> output_iterator transform( input_iterator start, input_iterator end, output_iterator result, UnaryFunction f ); output_iterator transform( input_iterator start1, input_iterator end1, input_iterator2 start2, output_iterator result, BinaryFunction f );
The transform() algorithm applies the function f to some range of elements, storing the result of each application of the function in result.
The first version of the function applies f to each element in [start,end) and assigns the first output of the function to result, the second output to (result+1), etc.
The second version of the transform() works in a similar manner, except that it is given two ranges of elements and calls a binary function on a pair of elements.
For example, the following code uses transform() to convert a string to uppercase using the standard C library toupper function:
string s("hello"); transform(s.begin(), s.end(), s.begin(), toupper); cout << s << endl;
The above code displays the following output:
HELLO