fork download
  1. #include <memory>
  2. #include <iostream>
  3.  
  4. int main()
  5. {
  6. std::default_delete<int> d;
  7. std::unique_ptr<int> u1;
  8. std::cout << "u1: " << (u1 ? "not null" : "null") << '\n';
  9.  
  10. std::unique_ptr<int> u2(nullptr);
  11. std::cout << "u2: " << (u2 ? "not null" : "null") << '\n';
  12.  
  13. std::unique_ptr<int> u3(new int);
  14. std::cout << "u3: " << (u3 ? "not null" : "null") << '\n';
  15.  
  16. std::unique_ptr<int> u4(new int, d);
  17. std::cout << "u4: " << (u4 ? "not null" : "null") << '\n';
  18.  
  19. std::unique_ptr<int> u5(new int, std::default_delete<int>());
  20. std::cout << "u5: " << (u5 ? "not null" : "null") << '\n';
  21.  
  22. std::unique_ptr<int> u6(std::move(u5));
  23. std::cout << "u6: " << (u6 ? "not null" : "null") << '\n';
  24.  
  25. std::unique_ptr<int> u7(std::move(u6));
  26. std::cout << "u7: " << (u7 ? "not null" : "null") << '\n';
  27. }
Success #stdin #stdout 0s 4568KB
stdin
Standard input is empty
stdout
u1: null
u2: null
u3: not null
u4: not null
u5: not null
u6: not null
u7: not null