1 #ifndef MSP_CORE_RAII_H_
2 #define MSP_CORE_RAII_H_
7 Sets a value for the duration of a scope. The old value is restored when the
18 SetForScope(T &r, T v): ref(r), old(r) { ref = v; }
19 ~SetForScope() { ref = old; }
22 class SetFlag: public SetForScope<bool>
25 SetFlag(bool &r, bool v = true): SetForScope<bool>(r, v) { }
38 Conditional(bool c, const A &a): obj(c ? new(buf) T(a) : 0) { }
40 template<typename A0, typename A1>
41 Conditional(bool c, const A0 &a0, const A1 &a1): obj(c ? new(buf) T(a0, a1) : 0) { }
43 ~Conditional() { if(obj) obj->~T(); }