mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 01:41:59 -05:00
AK: Add a TemporaryChange helper class.
This commit is contained in:
parent
8cc6e304ca
commit
781f216676
1 changed files with 18 additions and 0 deletions
18
AK/TemporaryChange.h
Normal file
18
AK/TemporaryChange.h
Normal file
|
@ -0,0 +1,18 @@
|
|||
#pragma once
|
||||
|
||||
namespace AK {
|
||||
|
||||
template<typename T>
|
||||
class TemporaryChange {
|
||||
public:
|
||||
TemporaryChange(T& variable, T value) : m_variable(variable), m_old_value(variable) { m_variable = value; }
|
||||
~TemporaryChange() { m_variable = m_old_value; }
|
||||
|
||||
private:
|
||||
T& m_variable;
|
||||
T m_old_value;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
using AK::TemporaryChange;
|
Loading…
Reference in a new issue