Imported Upstream version 14.45.0
[platform/upstream/libzypp.git] / zypp / AutoDispose.h
index 62562fd..bb01549 100644 (file)
@@ -33,10 +33,10 @@ namespace zypp
    *
    * \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
    * {
@@ -102,18 +102,20 @@ namespace zypp
       /** 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. */
@@ -135,7 +137,7 @@ namespace zypp
       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; }
 
@@ -156,9 +158,9 @@ namespace zypp
       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 )
@@ -167,13 +169,16 @@ namespace zypp
     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;