Talk:cpp/algorithm/for each

Is the following line correct? std::vector nums{3, 4, 2, 9, 15, 267};

It doesn't work with me, I'm using: g++ -std=c++0x to build.

I have to explicitly use std::vector.
 * Thanks for spotting that out. Now it's fixed.P12 14:37, 24 August 2011 (PDT)

for_each with object as third argument
Hi, I'm learning cpp, so I am not good enough to edit this section, but when learning for_each function from this section, I had some difficulty to understand the following line from the example

Sum s = std::for_each(nums.begin, nums.end, Sum);

After searching in the web, I finally found that the third argument "UnaryFunction f" can be a class/struct instance that has a public unary operator which is taken by value and a copy of it is returned by for_each.

I suggest to clarify this point at the for_each section.

Thanks 82.67.68.32 04:22, 20 October 2013 (PDT)


 * Thanks for the comment. I've added a comment and expanded the example description to try to make it a bit clearer. --Nate (talk) 08:24, 21 October 2013 (PDT)