Advertisement
Guest User

Untitled

a guest
Sep 4th, 2015
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. DeepPtr( const T& value ) :myPtr( new T{ value } ) {}
  2.  
  3. DeepPtr( const DeepPtr& other )
  4. :myPtr( nullptr )
  5. {
  6. if ( other )
  7. {
  8. myPtr = std::unique_ptr<T>{ new T{ *other } };
  9. }
  10. }
  11.  
  12. DeepPtr( DeepPtr&& other )
  13. :myPtr( nullptr )
  14. {
  15. if ( other )
  16. {
  17. myPtr = std::unique_ptr<T>{ new T{ *other } };
  18. }
  19. }
  20.  
  21. DeepPtr& operator=( const DeepPtr& other )
  22. {
  23. DeepPtr temp{ other };
  24. swap( *this, temp );
  25. return *this;
  26. }
  27.  
  28. DeepPtr& operator=( DeepPtr&& other )
  29. {
  30. swap( *this, other );
  31. return *this;
  32. }
  33.  
  34. static void swap( DeepPtr& left, DeepPtr& right ) { std::swap( left.myPtr, right.myPtr ); }
  35.  
  36. T& operator*() { return *myPtr; }
  37.  
  38. const T& operator*() const { return *myPtr; }
  39.  
  40. T* const operator->() { return myPtr.operator->(); }
  41.  
  42. const T* const operator->() const { return myPtr.operator->(); }
  43.  
  44. const T* const get() const { return myPtr.get(); }
  45.  
  46. operator bool() const { return (bool)myPtr; }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement