libzypp 17.31.23
zypp::DtorReset Class Reference

Assign a vaiable a certain value when going out of scope. More...

#include <base/dtorreset.h>

Classes

struct  Impl
 Requires TVal being copy constructible, and assignment TVar = TVal defined. More...
 

Public Member Functions

 DtorReset ()
 
template<class TVar >
 DtorReset (TVar &var_r)
 
template<class TVar , class TVal >
 DtorReset (TVar &var_r, const TVal &val_r)
 

Private Attributes

shared_ptr< void > _pimpl
 

Detailed Description

Assign a vaiable a certain value when going out of scope.

Use it e.g. to reset/cleanup in presence of exceptions.

struct Foo
{
void consume()
{
DtorReset x(_inConsume,false);
_inConsume = true;
MIL << _inConsume << endl;
};
};
Foo f;
MIL << f._inConsume << endl; // 0
f.consume(); // 1
MIL << f._inConsume << endl; // 0
Integral type with defined initial value when default constructed.
Assign a vaiable a certain value when going out of scope.
Definition: dtorreset.h:50
#define MIL
Definition: Logger.h:96
Todo:
Check if using call_traits enables 'DtorReset(std::string,"value")', as this currently would require assignment of 'char[]'.

Definition at line 49 of file dtorreset.h.

Constructor & Destructor Documentation

◆ DtorReset() [1/3]

zypp::DtorReset::DtorReset ( )
inline

Definition at line 52 of file dtorreset.h.

◆ DtorReset() [2/3]

template<class TVar >
zypp::DtorReset::DtorReset ( TVar &  var_r)
inline

Definition at line 55 of file dtorreset.h.

◆ DtorReset() [3/3]

template<class TVar , class TVal >
zypp::DtorReset::DtorReset ( TVar &  var_r,
const TVal &  val_r 
)
inline

Definition at line 59 of file dtorreset.h.

Member Data Documentation

◆ _pimpl

shared_ptr<void> zypp::DtorReset::_pimpl
private

Definition at line 78 of file dtorreset.h.


The documentation for this class was generated from the following file: