#include "unique_ptr.hpp" #include #include void demoUniquePointer(); // ------------------------------------------------------------------ // // usu::unique_ptr final test // // ------------------------------------------------------------------ int main() { demoUniquePointer(); return 0; } void demoUniquePointer() { std::unique_ptr p1 = std::make_unique(10); usu::unique_ptr p2 = usu::make_unique(10); // TEST: Uncomment the following lines, they should cause a compiler error! //std::unique_ptr p1b = p1; // Causes a compile error (and it should) //usu::unique_ptr p2b = p2; // Causes a compile error (and it should) std::cout << "from *p1 : " << *p1 << std::endl; std::unique_ptr p3; p3 = std::move(p1); // TEST: Uncomment the following line, it should cause a runtime error! //std::cout << *p1 << std::endl; // Causes a runtime error (and it should) std::cout << "from *p3 : " << *p3 << std::endl; std::cout << "from *p2 : " << *p2 << std::endl; usu::unique_ptr p4; p4 = std::move(p2); std::cout << "from *p4 : " << *p4 << std::endl; // TEST: Uncomment the following line, it should cause a runtime error! //std::cout << *p2 << std::endl; // Causes a runtime error (and it should) }