#include #include // smart pointers #include #include // move using std::unique_ptr; using std::string; template struct Del { void operator()(T* p) { std::cout << "Del deleting " << *p << '\n'; delete p; } }; template void print(const T* p) { if (p) std::cout << *p << " "; else std::cout << "null "; } int main() { unique_ptr> p1{new string{"abcde"}, Del{}}, p2{new string{"vwxyz"}, Del{}}; print(p1.get()); print(p2.get()); std::cout << '\n'; std::cout << "Now moving\n"; p1 = std::move(p2); std::cout << "After moving\n"; print(p1.get()); print(p2.get()); std::cout << '\n'; std::cout << "Exiting from main\n"; }