1 #ifndef AFTL_MTP_SCOPE_GUARD_H 2 #define AFTL_MTP_SCOPE_GUARD_H 3 4 #include <functional> 5 #include <mtp/types.h> 6 7 namespace mtp 8 { 9 class scope_guard : Noncopyable 10 { 11 using Callback = std::function<void ()>; 12 Callback _callback; 13 14 public: scope_guard(Callback && c)15 scope_guard(Callback && c): _callback(c) 16 { } 17 ~scope_guard()18 ~scope_guard() 19 { _callback(); } 20 }; 21 22 } 23 24 #endif 25