Skip to content

Commit

Permalink
AK: Add a TemporaryChange helper class.
Browse files Browse the repository at this point in the history
  • Loading branch information
awesomekling committed Feb 6, 2019
1 parent 8cc6e30 commit 781f216
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions AK/TemporaryChange.h
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 781f216

Please sign in to comment.