// std::for_each works essentially like this #include template Func for_each(Iter first, Iter last, Func f) { while (first!=last) { f (*first); ++first; } return std::move(f); }