#include #include #include struct TRIPLE { void operator()(int& i) { i*=3; } }; template struct PRINTER { void operator() (T& item) { std::cout << item << std::endl; } }; int main(int argc, char** argv) { std::vector v; for (int i = 0; i < 10; i++) { v.push_back(i); } // print before std::for_each(v.begin(), v.end(), PRINTER()); // triple all the members std::for_each(v.begin(), v.end(), TRIPLE()); std::cout << "++++++++++++++++++++++++++++++++++++++++++++++++++" << std::endl; // print after std::for_each(v.begin(), v.end(), PRINTER()); return 0; }