Are there any advantages of std::for_each over for
loop? To me, std::for_each
only seems to hinder the readability of code. Why do then some coding
its very subjective, some will say that using for_each
will make the code more readable, as it allows to treat different collections with the same conventions.
for_each
itslef is implemented as a loop
template
Function for_each(InputIterator first, InputIterator last, Function f)
{
for ( ; first!=last; ++first ) f(*first);
return f;
}
so its up to you to choose what is right for you.