The simplest and neatest c++11 ScopeGuard

Even shorter: I don’t know why you guys insist on putting the template on the guard class. #include <functional> class scope_guard { public: template<class Callable> scope_guard(Callable && undo_func) try : f(std::forward<Callable>(undo_func)) { } catch(…) { undo_func(); throw; } scope_guard(scope_guard && other) : f(std::move(other.f)) { other.f = nullptr; } ~scope_guard() { if(f) f(); // must not … Read more