Add mode to AutoRestoreBackup to not change backed up value
This commit is contained in:
@@ -144,6 +144,8 @@ private:
|
|||||||
const int line;
|
const int line;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct AutoRestoreBackupNoNewValueTag {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to backup a specific variable and restore it upon destruction of this object to prevent
|
* Class to backup a specific variable and restore it upon destruction of this object to prevent
|
||||||
* stack values going out of scope before resetting the global to its original value. Contrary to
|
* stack values going out of scope before resetting the global to its original value. Contrary to
|
||||||
@@ -157,6 +159,13 @@ struct AutoRestoreBackup {
|
|||||||
* the whole goal and reason for existing of this object.
|
* the whole goal and reason for existing of this object.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Backup variable.
|
||||||
|
* @param original Variable to backup.
|
||||||
|
* @param tag Tag to indicate that the variable's value should not be changed.
|
||||||
|
*/
|
||||||
|
AutoRestoreBackup(T &original, AutoRestoreBackupNoNewValueTag tag) : original(original), original_value(original) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Backup variable and switch to new value.
|
* Backup variable and switch to new value.
|
||||||
* @param original Variable to backup.
|
* @param original Variable to backup.
|
||||||
|
Reference in New Issue
Block a user