QtBase
v6.3.1
|
The QScopedValueRollback class resets a variable to its previous value on destruction. More...
#include <qscopedvaluerollback.h>
Public Member Functions | |
constexpr | QScopedValueRollback (T &var) |
constexpr | QScopedValueRollback (T &var, T value) |
~QScopedValueRollback () | |
constexpr void | commit () |
The QScopedValueRollback class resets a variable to its previous value on destruction.
\inmodule QtCore
The QScopedValueRollback class can be used to revert state when an exception is thrown without needing to write try-catch blocks.
It can also be used to manage variables that are temporarily set, such as reentrancy guards. By using this class, the variable will be reset whether the function is exited normally, exited early by a return statement, or exited by an exception.
The template can only be instantiated with a type that supports assignment.
Definition at line 48 of file qscopedvaluerollback.h.
|
inlineexplicitconstexpr |
Stores the previous value of var internally, for revert on destruction.
Definition at line 51 of file qscopedvaluerollback.h.
|
inlineexplicitconstexpr |
Assigns value to \ var and stores the previous value of var internally, for revert on destruction.
Definition at line 56 of file qscopedvaluerollback.h.
|
inline |
Assigns the previous value to the managed variable. This is the value at construction time, or at the last call to commit()
Definition at line 64 of file qscopedvaluerollback.h.
|
inlineconstexpr |
Updates the previous value of the managed variable to its current value.
Definition at line 69 of file qscopedvaluerollback.h.