http://www.cplusplus.com/reference/algorithm/for_each/
#include <iostream> #include <list> #include <algorithm> using namespace std; template <class T> void print(T &t) { cout<<t; } template <class T> class Print { public: void operator()(T&t) { cout<<t; } }; int main() { list <int> L; for (int i=1;i <=7;i++) L.push_front(i); for_each(L.begin(),L.end(),print<int> ); cout<<endl; for_each(L.begin(),L.end(),Print<int>() ); return 1; }