| 123456789101112131415161718192021222324 |
- //
- // scope_exit.hpp
- // gameutils
- //
- // Created by Sam Jaffe on 7/5/16.
- //
- #pragma once
- #include <functional>
- #include "macro.h"
- #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;
- };
|