#include <iostream> #include <vector> #include <algorithm> template <typename T> class print{ public: void operator()(const T& iter) const { std::cout<<iter; return; } }; int main(){ std::vector<int> v1, v2; v1.push_back(1); v1.push_back(2); v2.push_back(3); v2.push_back(4); v2.push_back(5); std::cout<<v2.size()<<std::endl; v2.assign(v1.begin(), v1.end()); //clear + intsert, relloc std::cout<<v2.size()<<std::endl; try{ for_each(v2.begin(), v2.end(), print<int>()); }catch(std::exception& e){ e.what(); } std::cout<<std::endl; return 0; }