Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. namespace std {
  2.  
  3. class string
  4. {
  5. private:
  6. char *_M_string;
  7. size_t _M_size;
  8. // as you can see, std::string is basically just a wrapper
  9. // around char * and size
  10.  
  11. public:
  12. // this constructs an empty string
  13. string()
  14. : _M_string(nullptr), _M_size(0) { }
  15.  
  16. // this will actually copy the string, so it's not interesting to us...
  17. string(const string &other);
  18.  
  19. // this is the constructor that will be called when you use std::move
  20. string(string &&other)
  21. : string() // <-- construct an empty string first
  22. {
  23. swap(_M_string, other._M_string);
  24. swap(_M_size, other._M_size);
  25. // and now "other" string is empty and "this" string has its content
  26. }
  27.  
  28. ~string()
  29. {
  30. // deleting a nullptr is fine
  31. delete [] _M_string;
  32. }
  33.  
  34. //... other stuff
  35. };
  36.  
  37. } // std
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement