I know transform
algorithm in C++ is a mutating sequence algorithm
. But I have never seen anyone using transform
for the purpose of mutating a sequence. Whenever I search for a sample code on internet, what I get is the transform algorithm used similar to for_each
algorithm.
Please provide a link or an example , where I can understand the mutating sequence
nature.
Edit: I got more confused when I went through This SO question.
it says for_each
is a non-modifying sequence
algorithm. So I can modify the elements with for_each
not the structure of the container.Is the provided answer incorrect. If for_each
can also modify the element, we can replace for_each
with transform
,and there is no need of for_each
algorithm except that it's implementation may be simple.