Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DeepPtr( const T& value ) :myPtr( new T{ value } ) {}
- DeepPtr( const DeepPtr& other )
- :myPtr( nullptr )
- {
- if ( other )
- {
- myPtr = std::unique_ptr<T>{ new T{ *other } };
- }
- }
- DeepPtr( DeepPtr&& other )
- :myPtr( nullptr )
- {
- if ( other )
- {
- myPtr = std::unique_ptr<T>{ new T{ *other } };
- }
- }
- DeepPtr& operator=( const DeepPtr& other )
- {
- DeepPtr temp{ other };
- swap( *this, temp );
- return *this;
- }
- DeepPtr& operator=( DeepPtr&& other )
- {
- swap( *this, other );
- return *this;
- }
- static void swap( DeepPtr& left, DeepPtr& right ) { std::swap( left.myPtr, right.myPtr ); }
- T& operator*() { return *myPtr; }
- const T& operator*() const { return *myPtr; }
- T* const operator->() { return myPtr.operator->(); }
- const T* const operator->() const { return myPtr.operator->(); }
- const T* const get() const { return myPtr.get(); }
- operator bool() const { return (bool)myPtr; }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement