From 85889143c739bf5fdaff6fb71a901c87b79cc942 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Wed, 15 Feb 2023 21:13:07 +0000 Subject: [PATCH] Add mode to AutoRestoreBackup to not change backed up value --- src/core/backup_type.hpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/core/backup_type.hpp b/src/core/backup_type.hpp index 23beedefb4..cce6ddb8d1 100644 --- a/src/core/backup_type.hpp +++ b/src/core/backup_type.hpp @@ -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.