fork download
  1. #include <memory>
  2. #include <type_traits>
  3.  
  4.  
  5. template<typename T>
  6. class Container {
  7. T t;
  8. public:
  9. Container() = default;
  10.  
  11. Container(const Container& other) = default;
  12.  
  13. Container(Container&& other) : t(std::move(other.t)) {}
  14. };
  15.  
  16. static_assert(std::is_copy_constructible<Container<int>>::value, "Non-Copyable");
  17. static_assert(!std::is_copy_constructible<Container<std::unique_ptr<int>>>::value, "Copyable");
  18.  
  19. Container<std::unique_ptr<int>> makeNonCopyableContainer() {
  20. return Container<std::unique_ptr<int>>();
  21. }
  22.  
  23. int main () {
  24. Container<int> c1;
  25. Container<int> c2(c1);
  26. Container<std::unique_ptr<int>> c3;
  27. // This would generate compile error:
  28. // Container<std::unique_ptr<int>> c4(c3);
  29. Container<std::unique_ptr<int>> c5(makeNonCopyableContainer());
  30. return 0;
  31. }
Success #stdin #stdout 0s 3336KB
stdin
Standard input is empty
stdout
Standard output is empty