| 1234567891011121314151617181920212223242526 |
- //
- // scope_exit.hpp
- // gameutils
- //
- // Created by Sam Jaffe on 7/5/16.
- //
- #pragma once
- #include <functional>
- #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 <typename F>
- 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<void()> _func;
- };
|