2020-01-18 11:38:21 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 11:38:21 +03:00
|
|
|
*/
|
|
|
|
|
2019-02-06 18:01:59 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
namespace AK {
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
class TemporaryChange {
|
|
|
|
public:
|
2019-05-28 12:53:16 +03:00
|
|
|
TemporaryChange(T& variable, T value)
|
|
|
|
: m_variable(variable)
|
|
|
|
, m_old_value(variable)
|
|
|
|
{
|
|
|
|
m_variable = value;
|
|
|
|
}
|
2019-02-06 18:01:59 +03:00
|
|
|
~TemporaryChange() { m_variable = m_old_value; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
T& m_variable;
|
|
|
|
T m_old_value;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
using AK::TemporaryChange;
|