C++ (Qt)template< typename _Type >class InstancePtr{ using ThisType = InstancePtr< _Type >; using RawPtr = _Type *; using RawRef = _Type &; using ConstRawPtr = const _Type *; using ConstRawRef = const _Type &; RawPtr m_pointer; public: template < typename ... _Arguments > InstancePtr ( _Arguments && ... arguments ) : m_pointer( new _Type( ::std::forward< _Arguments >( arguments ) ... ) ) {} InstancePtr ( ThisType && other ) : m_pointer( ::std::forward< PointerType >( other.m_pointer ) ) { other.m_pointer = nullptr; } InstancePtr ( const ThisType & other ) : InstancePtr( *other.m_pointer ) {} ~InstancePtr () { delete m_pointer; } RawRef operator * () { return *m_pointer; } RawPtr operator -> () { return m_pointer; } ConstRawRef operator * () const { return *m_pointer; } ConstRawPtr operator -> () const { return m_pointer; }};
C++ (Qt)std::unique_ptr<SomeClass> makeCopy(const std::unique_ptr<SomeClass>& from);