fork download
  1. #include <iostream>
  2.  
  3. class String
  4. {
  5. char* data;
  6. int len;
  7. public:
  8. // Normal rule of three applied up here.
  9. void swap(String& rhs) throw()
  10. {
  11. std::swap(data, rhs.data);
  12. std::swap(len, rhs.len);
  13. }
  14. String& operator=(const String& rhs) // Standard Copy and swap.
  15. {
  16. //rhs.swap(*this);
  17. return *this;
  18. }
  19.  
  20. // New Stuff here.
  21. // Move constructor
  22. String(String&& cpy) throw() // ignore old throw construct for now.
  23. : data(NULL)
  24. , len(0)
  25. {
  26. *this = std::forward<String>(cpy);
  27. }
  28. String& operator=(String&& rhs) noexcept
  29. {
  30. rhs.swap(*this);
  31. return *this;
  32. }
  33. };
  34.  
  35. int main()
  36. {
  37. return 0;
  38. }
Success #stdin #stdout 0s 3292KB
stdin
Standard input is empty
stdout
Standard output is empty