Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
std::transform is an algorithm to perform a modifying function on the elements of a sequence (on a std::vector, for example). Use std::for_each to perform non-modifying functions on the elements of a sequence.
Prefer algorithms over hand-written loops [0][1][2]. View Exercise #9: No for-loops to learn how to remove hand-written loops .
std::transform does not use a predicate. Use Transform_if if a predicate is needed.
The code below shows a simple way to multiply all elements in a std::vector by a certain value:
#include <vector> |
std::transform can be used to replace the for-loop in the example below:
#include <algorithm> |
Simplified from the STL that ships with C++ Builder 6.0:
template |
std::transform does not use a predicate. Use Transform_if if a predicate is needed.
Go back to Richel Bilderbeek's C++ page.
Go back to Richel Bilderbeek's homepage.
This page has been created by the tool CodeToHtml