template <class Ref, class Deleter>struct CScopedRef {..
C++ (Qt)template <typename TRef, typename TDeleter>struct CScopedRef { CScopedRef( TRef * ref ) : mRef(ref) {} ~CScopedRef( void ) { if (mRef) TDeleter(mRef); } operator TRef * ( void ) { return mRef; } void operator = ( TRef * ref ) { if (mRef != ref) { if (mRef) TDeleter(mRef); mRef = ref; } } private: TRef * mRef; CScopedRef( const CScopedRef & ) {} void operator = ( const CScopedRef & ) {}}; typedef CScopedRef <OpaqueRef, DestroyOpaqueRef> CScopedOpaqueRef;
C++ (Qt)template <typename TRef, typename TDeleter = default_deleter>struct CScopedRef { CScopedRef( TRef * ref, TDeleter deleter) : mRef(ref), mDeleter(deleter) {} CScopedRef( TRef * ref) : mRef(ref) {} ~CScopedRef( void ) { if (mRef) mDeleter(mRef); } operator TRef * ( void ) { return mRef; } void operator = ( TRef * ref ) { if (mRef != ref) { if (mRef) mDeleter(mRef); mRef = ref; } } private: TRef * mRef; TDeleter mDeleter; CScopedRef( CScopedRef & ) void operator = ( CScopedRef & )};
C++ (Qt)typedef void (*FunctionType)(Ref *);CScopedRef<Ref, FunctionType> ref(new Rew, DestroyOpaqueRef);
C++ (Qt)template<typename T, void (*destroyer)( T )>struct CScopedRef {{public: ~CScopedRef() { destroyer( mRef ); }
C++ (Qt)typedef unsigned int HANDLE; HANDLE create( ... );destroy( HANDLE );
C++ (Qt)CScoped<Data *, DestroyData> d1 = CreateData( ... );CScoped<HANDLE, destroy> d2 = create( ... );
C++ (Qt)template <typename TRef, void (*delFunc)(TRef *)>struct CScopedRef { CScopedRef( TRef * ref ) : mRef(ref) {} ~CScopedRef( void ) { if (mRef) delFunc(mRef); } operator TRef * ( void ) { return mRef; } void operator = ( TRef * ref ) { if (mRef != ref) { if (mRef) delFunc(mRef); mRef = ref; } } private: TRef * mRef; CScopedRef( const CScopedRef & ) {} void operator = ( const CScopedRef & ) {}}; typedef CScopedRef <OpaqueRef, DestroyOpaqueRef> CScopedOpaqueRef;
C++ (Qt)OpaqueRef * src = CreateOpaqueRef();CScopedOpaqueRef ref1(src); // ОкCScopedOpaqueRef ref2 = src; // error
Some obj = 10;
Some obj = Some(10);
Some obj ( Some(10) );