Add mode to AutoRestoreBackup to not change backed up value

This commit is contained in:
Jonathan G Rennison
2023-02-15 21:13:07 +00:00
parent 2b4b2f605d
commit 85889143c7

View File

@@ -144,6 +144,8 @@ private:
const int line;
};
struct AutoRestoreBackupNoNewValueTag {};
/**
* 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
@@ -157,6 +159,13 @@ struct AutoRestoreBackup {
* 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.
* @param original Variable to backup.