--- /dev/null
+#ifndef MSP_CORE_RAII_H_
+#define MSP_CORE_RAII_H_
+
+namespace Msp {
+
+/**
+Sets a value for the duration of a scope. The old value is restored when the
+scope ends.
+*/
+template<typename T>
+class SetForScope
+{
+private:
+ T &ref;
+ T old;
+
+public:
+ SetForScope(T &r, T v): ref(r), old(r) { ref = v; }
+ ~SetForScope() { ref = old; }
+};
+
+class SetFlag: public SetForScope<bool>
+{
+public:
+ SetFlag(bool &r, bool v = true): SetForScope<bool>(r, v) { }
+};
+
+} // namespace Msp
+
+#endif