Q:

C++ for loop style to invoke specific member function of object

To iterate a array to invoke the specific method of each element.
(a). Index Style
for(std::size_t i = 0; i < my_objs.size(); i++)
{
    my_objs[i].do_something();
}

(b). Iterator style
for(std::vector<MyObject>::const_iterator iter = my_objs.begin();
    iter != my_objs.end(); iter++)
{
    iter->do_something();
}

(c). STL Style
std::for_each(my_objs.begin(), my_objs.end(), [](const MyObject& obj){ obj.do_something(); });

(d). C++ 11 for-loop style
for(const auto& obj: my_objs)
{
    obj.do_something();
}

Many C++ books told me, use STL whenever you can. But compared (c) to (d), the STL style for-loop need additional iterator pair and the parameter type definition of lambda so that the std::for_each becomes too long to read easily. It looks the (d) way is more clearer and less types. 
Which one has the better readability? or any better style to represent that to invoke the member function of each object in a vector?

A:

The algorithmic style may be appropriate if you have a very simple task such as calling a nullary member function:
std::for_each(my_objs.cbegin(), my_objs.cend(),
              std::mem_fn(&MyObject::do_something));

Otherwise feel free to use the range-based loop, which is perfectly acceptable for small units of work. As always use your judgement and refactor when you find that any one block is doing too much work.

