// note: can't store the originalValue in a ValueRestorationGuard member, // because it will be used from base class dtor template <typename T> struct ValueRestorationGuard_Impl
{
T& rVal;
T const originalValue;
ValueRestorationGuard_Impl(T& i_valRef)
: rVal(i_valRef), originalValue(i_valRef) {} voidoperator()()
{
rVal = originalValue;
}
};
template <typename T> class ValueRestorationGuard : public ScopeGuard<ValueRestorationGuard_Impl<T>>
{ public:
ValueRestorationGuard(T& i_valRef)
: ScopeGuard<ValueRestorationGuard_Impl<T>>(ValueRestorationGuard_Impl(i_valRef))
{}
// Guarantees that the flag is true within the scope of the guard, and is set to false after // its destruction, regardless of initial flag value class FlagGuard : public FlagRestorationGuard
{ public: // Set flag to false before passing its reference to base class ctor, so that it would be // reset back to false in base class dtor explicit FlagGuard(bool& i_flagRef)
: FlagRestorationGuard((i_flagRef = false), true)
{
}
};
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.