Both can be used to apply a function to a range of elements.
On a high level:
std::for_each
ignores the return value of the function, and
guarantees order of execution.std::transform
assigns the return value to the iterator, and does
not guarantee the order of execution.When do you prefer using the one versus the other? Are there any subtle caveats?