*
* \note As with pointers, constness of an \c AutoDispose object does
* \b not apply to the stored \c _Tp object. If the stored \c _Tp object
- * should be immutable, you should use <tt>AutoDispose\<const _Tp\><\tt>.
+ * should be immutable, you should use <tt>AutoDispose\<const _Tp\></tt>.
*
* Pass a filename to the application and provide the appropriate
- * code to be exectued when the file is no longer needed:
+ * code to be executed when the file is no longer needed:
* \code
* struct FileCache
* {
/** Dispose function signatue. */
typedef function<void ( param_type )> Dispose;
- /** Noop dispose function. */
- static void nodispose( param_type ) {}
-
public:
- /** Default Ctor using default constructed value and \ref nodispose function. */
+ /** Default Ctor using default constructed value and no dispose function. */
AutoDispose()
- : _pimpl( new Impl( value_type(), nodispose ) )
+ : _pimpl( new Impl( value_type() ) )
+ {}
+
+ /** Ctor taking dispose function and using default constructed value. */
+ explicit AutoDispose( const Dispose & dispose_r )
+ : _pimpl( new Impl( value_type(), dispose_r ) )
{}
- /** Ctor taking value and using \ref nodispose function. */
- AutoDispose( param_type value_r )
- : _pimpl( new Impl( value_r, nodispose ) )
+ /** Ctor taking value and no dispose function. */
+ explicit AutoDispose( param_type value_r )
+ : _pimpl( new Impl( value_r ) )
{}
/** Ctor taking value and dispose function. */
reference operator*() const
{ return _pimpl->_value; }
- /** Pointer to the \c _Tp object (asserted to be <tt>!= NULL<\tt>). */
+ /** Pointer to the \c _Tp object (asserted to be <tt>!= NULL</tt>). */
value_type * operator->() const
{ return & _pimpl->_value; }
void setDispose( const Dispose & dispose_r )
{ _pimpl->_dispose = dispose_r; }
- /** Set \ref nodispose function. */
+ /** Set no dispose function. */
void resetDispose()
- { setDispose( nodispose ); }
+ { setDispose( Dispose() ); }
/** Exchange the dispose function. +*/
void swapDispose( Dispose & dispose_r )
private:
struct Impl : private base::NonCopyable
{
+ Impl( param_type value_r )
+ : _value( value_r )
+ {}
Impl( param_type value_r, const Dispose & dispose_r )
: _value( value_r )
, _dispose( dispose_r )
{}
~Impl()
{
- if ( _dispose != nodispose )
+ if ( _dispose )
try { _dispose( _value ); } catch(...) {}
}
value_type _value;