// // scope_exit.hpp // gameutils // // Created by Sam Jaffe on 7/5/16. // #pragma once #include #undef CONCAT2 #define CONCAT2(A, B) A##B #undef CONCAT #define CONCAT(A, B) CONCAT2(A, B) #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; };