// // scope_exit.hpp // gameutils // // Created by Sam Jaffe on 7/5/16. // #pragma once #include #include "macro.h" #define scope(type) scope_##type##_t CONCAT( scope_,CONCAT( type, __LINE__ ) ) = [&]() class scope_exit_t { public: template scope_exit_t(F && fun) : _func(fun) {} scope_exit_t(scope_exit_t && other) : _func(std::move(other._func)) {} ~scope_exit_t() { _func(); } private: std::function _func; };